jquery background change one axis only

*爱你&永不变心* 提交于 2019-12-05 06:55:02

Here's how I would do it.

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

Add the 2 values to background-position (as it expects). Also save the current position in a variable which makes this easier.

var pos = -377;
var colorChangePiano = function() {
  if (pos == -377) {
    pos = -1131
  }
  else {
    pos = -377
  }
  $('#target').css({
    'backround-position': pos + 'px 0px' // will result in "Xpx 0px"
  });
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!