2011-01-08 11 views
0

これはインターネットから入手したスクリプトで、完全に動作します。この場合はdivの上でマウスの動きに自動的にスクロールしますscrollしかし、私はどこで見つけることができるようです速度を遅くすることができます!私は困惑している!!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関数は呼び出されません。これを実現するには、おそらくjQuery animate()関数をmarginTop CSSで使用して、そのコードを書き直す必要があります。

唯一の問題は、コードがmousemoveで呼び出されるということです。これは、アニメーションがまだアクティブな間に再び呼び出される可能性があることを意味します。アニメーションがあるかどうか最初にチェックし、その場合は中止するなど、いくつかの回避策を考えなければなりません。

関連する問題