2013-09-16 30 views

回答

2

這是因爲this不是您的元素,而是您的回調中的window

下面就來解決這個問題的方式:

var myInterval 
$(".miniPosterImg").hover(function() { 
    var $this = $(this); 
    myInterval= setInterval(function(){ 
     thismarginLeft = $this.css("margin-left").replace(/[^0-9]/g,''); 
     if(thismarginLeft < 360){ 
       thismarginLeft = thismarginLeft-120; 
     //}else{ 
     //  thismarginLeft = 0; 
     } 
     $this.css("margin-left", thismarginLeft + "px"); 
    },1000); 
}, function(){ 
    clearInterval(myInterval) ; 
}); 

Demonstration

相關問題