2013-01-08 126 views
0

我想用jQuery動畫。我有這樣的代碼:jquery動畫不動畫

$(document).ready(function(){ 
$(".label").delay(2000).animate({backgroundPositionX:"0px",backgroundPositionY:"30px"},10000,linear); 
$(".label").animate({backgroundPositionX: "-70px" ,backgroundPositionY:"30px"},10000,linear); 
$(".label").animate({backgroundPositionX: "-140px" ,backgroundPositionY:"30px"},10000,linear); 

但動畫不起作用。任何想法出了什麼問題?

回答

2

SO question and answer將有所幫助。 backgroundPositionXbackgroundPositionY是不標準的,不適用於所有瀏覽器。

+0

我嘗試過所有瀏覽器都沒有結果。我將嘗試僅傳遞一個參數以用於背景位置。謝謝:) – Cheryl

0
$(document).ready(function() { 
    $(".label").delay(2000).animate({ 
    backgroundPositionX: "0px", 
    backgroundPositionY: "30px" 
    }, 10000, 'linear'); 
    $(".label").animate({ 
    backgroundPositionX: "-70px", 
    backgroundPositionY: "30px" 
    }, 10000, 'linear'); 
    $(".label").animate({ 
    backgroundPositionX: "-140px", 
    backgroundPositionY: "30px" 
    }, 10000, 'linear'); 
}); 

一個demo

+0

它對你有用嗎?因爲我看不到動畫 – Cheryl

1

我編輯我的代碼如下:

$(document).ready(function() { 
    $(".label").delay(2000).css({ 
    "backgroundPositionX": "0px", 
    "backgroundPositionY": "30px" 
    }, 5000, 'linear'); 
    $(".label").animate({ 
    "backgroundPositionX": "-70px", 
    "backgroundPositionY": "30px" 
    }, 5000, 'linear'); 
    $(".label").animate({ 
    "backgroundPositionX": "-140px", 
    "backgroundPositionY": "30px" 
    }, 5000, 'linear'); 
}); 

和它的作品爲