0
我有一個問題。我將這張3060像素的圖像作爲我的背景圖像,當我按菜單鏈接時,我想將背景向右或向左「滑動」,但是當我這樣做時,我只能使用X如果我使用backgroundPositionX,它不會做任何事情。但是,當我使用backgroundPosition時,我只能提供1個參數。我只想做一些事情到X方面而不是Y.jQuery backgroundPostion和動畫不僅可以獲得Y
我現在的代碼將Y自動設置爲50%,這不是想要的。
function move(space) {
image = 3060;
bodyWidth = $('body').width();
offset = 900 * space;
if(image - offset < bodyWidth)
offset = image - bodyWidth - 15;
console.log(offset);
console.log(bodyWidth);
$('body').animate({
backgroundPosition: -offset
}, 5000, function() {
console.log("animate complete");
});
//$('body').css('backgroundPosition', '-'+offset+'px 0px');
}
即使我backgroundPosition:「500px 50px」動畫dosn't工作。只有當我backgroundPosition:偏移量或只給出1個數字它的作品。 – Niclas 2011-04-17 20:20:25
http://snook.ca/technical/jquery-bg/看看這可能會幫助你 – Bene 2011-04-17 20:54:06