2011-01-08 4 views
0

Dies ist ein Skript, das ich aus dem Internet habe, und es funktioniert perfekt, was es deos scrollt automatisch auf die Bewegung der Maus, über ein div in diesem Fall scroll, aber ich cnt scheint zu finden, wo ich die finden kann Geschwindigkeit, oder kann es langsamer machen !! ich bin so verwirrt!!jquery scroll speed?

$("#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 */ 
     }); 

    }); 

Antwort

0

Der Code scheint nur zu direkt auf die Marge Einstellung:

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

Das heißt, es ruft keine scroll jquery Funktion auf, die leicht animiert werden könnte. Um das zu erreichen, müssten Sie den Code neu schreiben, wahrscheinlich mit der Funktion jquery animate() mit der marginTop css.

Das einzige Problem ist, dass der Code auf mousemove aufgerufen wird, was bedeutet, dass er leicht wieder aufgerufen werden kann, während die Animation noch aktiv ist. Sie müssen sich also einen Workaround ausdenken, indem Sie zum Beispiel zuerst prüfen, ob eine Animation vorhanden ist, und sie in diesem Fall abbrechen.