2012-04-26 88 views
0

我目前正在爲一所老派的c64團隊打造一個網站,我認爲這將很好地展現像老前奏一樣擺動的徽標。Jquery:搖擺徽標

我以爲我擁有它,但它擺動一個方式,然後回來,然後停下來。

下面的代碼:

jQuery(document).ready(function() { 
function right() { 
    $('header img').animate({ 
    left: '680px', 
    }, 5000, function() { 
    left() 
    }); 
} 
function left() { 
    $('header img').animate({ 
    left: '0px', 
    }, 5000, function() { 
    right() 
    }); 
} 
}); 

我敢肯定,我失去了一些東西簡單,任何幫助,將不勝感激。

+0

頁面jQuery開發週期在控制檯停止爲好,沒有錯誤。必須是某種動畫衝突? – 2012-04-26 14:55:42

回答

0

看起來這可能是一個範圍問題。嘗試定義就緒事件處理程序以外的功能,如下所示:

function right() { 
    $('header img').animate({ 
    left: '680px', 
    }, 5000, function() { 
     left(); 
    }); 
} 

function left() { 
    $('header img').animate({ 
    left: '0px', 
    }, 5000, function() { 
     right(); 
    }); 
} 

jQuery(document).ready(function() { 
    right(); 
}); 
+0

沒有修復它,當它停止時它也停止了jquery循環,控制檯中沒有錯誤。 – 2012-04-26 13:49:09

0

我認爲這是與動畫隊列有關的事情。我將stop()添加到t動畫中,現在它可以工作。所以,如果你想有你的頁面上的擺動標誌,下面的代碼:

jQuery(document).ready(function() { 
right(); 

    function right() { 
     $('#images img').stop().animate({ 
// Move the image right to the width of the container, minus the width of the image 
     left: '480px', 
     }, 5000, function() { 
     left() 
     }); 
    } 
    function left() { 
     $('#images img').stop().animate({ 
// Move back to the left 
     left: '0px', 
     }, 5000, function() { 
     right() 
     }); 
    } 

});