2011-01-08 97 views
0

這是一個腳本,我從互聯網上得到的,它完美的作品,它是什麼反效果自動滾動鼠標的移動,在這種情況下div div123在scroll,但我cnt似乎找到我在哪裏可以找到速度,或者可以讓它變慢!我很困惑!!jquery滾動速度?

$("#scroll").mousemove(function(e){ 
     /* The scrollable quote container */ 

     if(!this.hideDiv) 
     { 
      /* These variables are initialised only the firts time the function is run: */ 

      this.hideDiv = $(this); 
      this.scrollDiv = $('#scroll'); 

      this.pos = this.hideDiv.offset(); 
      this.pos.top+=20; 
      /* Adding a 20px offset, so that the scrolling begins 20px from the top */ 


      this.slideHeight = this.scrollDiv.height(); 

      this.height = this.hideDiv.height(); 
      this.height-=20; 
      /* Adding a bottom offset */ 

      this.totScroll = this.slideHeight-this.height; 
     } 

     this.scrollDiv.css({ 
      /* Remember that this.scrollDiv is a jQuery object, as initilised above */ 

      marginTop:'-'+this.totScroll*(Math.max(e.pageY-this.pos.top,0)/this.height)+'px' 
      /* Assigning a negative top margin according to the position of the mouse cursor, passed 
       with e.pageY; It is relative to the page, so we substract the position of the scroll container */ 
     }); 

    }); 

回答

0

代碼似乎是隻設置直接餘量:

marginTop: ' - ' + this.totScroll *(Math.max(e.pageY-this.pos.top,0)/ this.height)+'px'

也就是說,它不會調用任何可以輕鬆動畫的滾動jquery函數。爲了達到這個目的,你必須重寫那段代碼,可能會使用帶有marginTop css的jquery animate()函數。

唯一的問題是,代碼在mousemove上調用,這意味着它可以很容易地在動畫仍然活動時再次調用。因此,您必須在那裏提出一些解決方法,比如可能首先檢查是否存在動畫並在此情況下中止它。