2010-08-08 194 views
2

我正在開發一個攝影組合主題,並且在爲網站上的某個功能編寫jQuery時遇到了一些問題。我試圖完成的是讓它每隔一次單擊上一個和下一個圖標時,縮略圖的內聯列表向左或向右移動110px(單個縮略圖的寬度)。每個點擊動畫背景位置

$('.next').each(
    function(){ 
     $(this).bind (
      "click", 
      function(event){ 
       $('#thumbnailGallery ul').animate(
        {left:-110}, { 
         duration:'fast', 
         easing:'easeInSine' 
       }); 
      } 
     ); 
    } 
); 

$('.prev').each(
    function(){ 
     $(this).bind (
      "click", 
      function(event){ 
       $('#thumbnailGallery ul').animate(
        {left:110}, { 
         duration:'fast', 
         easing:'easeInSine' 
       }); 
      } 
     ); 
    } 
); 

我目前使用.each();函數使用onClick綁定動畫,但動畫僅出現一次。例如,如果我點擊。下一步它將動畫-110px,但是當我再次點擊它不會。 .prev也是如此。

回答

2

試試這個:

$('.next').each(
    function(){ 
     $(this).bind (
      "click", 
      function(event){ 
       $('#thumbnailGallery ul').animate(
        {left:"-=110px"}, { 
         duration:'fast', 
         easing:'easeInSine' 
       }); 
      } 
     ); 
    } 
); 

$('.prev').each(
    function(){ 
     $(this).bind (
      "click", 
      function(event){ 
       $('#thumbnailGallery ul').animate(
        {left:"+=110px"}, { 
         duration:'fast', 
         easing:'easeInSine' 
       }); 
      } 
     ); 
    } 
); 

應根據實例

+0

作品完美地工作,謝謝。 – nnash 2010-08-08 23:39:13