2014-10-03 2 views
0

다음 jquery 코드를 사용하여 느린 스크롤 애니메이션을 만듭니다. http://jsfiddle.net/fhj45f21/마우스 오버시 .scrollTop() 애니메이션을 일시 중지하는 방법은 무엇입니까? (jsfiddle included)

불행히도 마우스 오버시 애니메이션을 일시 중지하는 데 어려움이 있습니다. 누군가 좀 봐 주시고 저에게 힌트를 주시겠습니까?

function Scroller(y){ 

    this.times = 0; 
    this.moveInter = 0; 
    this.backInter = 0; 

    this.moveBack = function() { 

     var self = this; 
     clearInterval(this.moveInter); 
     this.backInter = setInterval(function() { 
      self.times -= 5; 
      y.scrollTop(self.times); 
      if (self.times == 0) { 
       return self.startMove(); 
      } 
     }, 1); 
    } 

    this.move = function() { 

     var self = this; 
     this.moveInter = setInterval(function() { 
      self.times++; 
      y.scrollTop(self.times); 
      if (self.times == 1200) { 
       return self.moveBack(); 
      } 
     }, 50); 
    } 

    this.startMove = function() { 
     this.times = 0; 
     var self = this; 
     if (this.backInter != null) { 
      clearInterval(this.backInter); 
     } 
     window.setTimeout(function() { 
      self.move(); 
     }, 1000); 
    } 
} 
jQuery('.textBox').each(function() { 

    y = jQuery(this); 
    var scroller = new Scroller(y); 
    scroller.startMove(); 

}); 

감사합니다. 여기

+0

을로 마우스를? http://api.jquery.com/stop/ –

답변

2

당신은 이동 : http://jsfiddle.net/nxk4vseq/ 는 y는 호버에 스크롤러를 중지하고 다시 시작하지 mousein에 대한 기능을 가진 y.hover 핸들러를 추가하고

var scrl=this; 
y.hover(function(){ 
    clearInterval(scrl.moveInter); 
},function(){ 
    scrl.move();  
}); 
+1

고마워,이게 완벽 해! 너무 간단 :) – Gena

관련 문제