jQuery的背景只改变一个轴 [英] jquery background change one axis only

查看:80
本文介绍了jQuery的背景只改变一个轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我的最后一个问题使每个人不知所措,所以我将简化

I think my last question overwhelmed everybody so I will simplify

我仅尝试更改x轴的背景位置.默认情况下,如果仅定义一个值,则另一个默认为50%,因此此功能:

I am attempting to change the background-position of the x-axis only. By default if only one value is defined, the other defaults to 50%, so this function:

function colorChangePiano() {
    var bp = $("background-position").css;
    $("#target").css('background-position', (bp == -1131) ? '-377' : '0');
}

返回背景位置:0 50%;

如何修改功能以更改x轴但保持y轴不变?

How can I modify the function to change x-axis but leave y-axis unchanged?

已编辑->这是针对具有4列4行的精灵,因此y轴应保持动态.此处的工作网站: http://www.avalonbyeaw.com 单击完成".我们在现场站点上使用了一些疯狂的复杂脚本,但无论如何我还是会把它留在这里,因为我仍然非常想找到解决这个问题的方法

edited --> this is for a sprite with 4 columns and 4 rows so the y-axis should remain dynamic. working site here: http://www.avalonbyeaw.com click "finishes." we got it working with some crazy complicated scripting on the live site, but i will leave this up here anyway because i would still really like to find a solution to this problem

推荐答案

这就是我要这样做的方式.

Here's how I would do it.

$('#target').css('background-position', function(i, backgroundPosition) {
    return backgroundPosition.replace(/\d+px/, '60px');
});

这篇关于jQuery的背景只改变一个轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆