2012-10-23 108 views
0

所以我有什麼是我想要不斷地動畫製作一個大圖像,而有人在頁面上JQuery的背景位置動畫無限

我現在要做的是:

$('.photobanner').animate({ 
    backgroundPosition:"(-10000px 0px)" 
}, 80000, 'linear'); 

這工程..但它似乎到了結束和停止..我可以做同樣的動畫無限?? ??

現在的作品----

var counter=0; 
function moveBG(y) 
{ 
    counter=counter-1000; 
    $('.photobanner').animate({ backgroundPosition:"("+counter+"px 0px)" }, 8000, 'linear',moveBG); 
} 

我定義將被遞增到無窮遠的計數器和所使用的該功能。

+0

如果圖像的結尾和開頭是相同的,您可以重置圖像並在動畫函數結束時重新開始動畫。 – JamesSwift

回答

3

你總是可以做這樣的事情:

function moveBG() 
{ 
    $('.photobanner').css({ backgroundPosition:"(0px 0px)"}); 
    $('.photobanner').animate({ backgroundPosition:"(-1000px 0px)" }, 8000, 'linear',moveBG); 
} 

這樣函數的回調重做功能。儘管如此,它必須是一個無形的圖像。

+0

以及它的權利,雖然我不得不編輯 (你可以看看;)) – mhyassin