简体   繁体   中英

jquery scroll speed?

this is a script i got from a the internet, and it works perfectly, what it deos it scrolls automatically on the movement of the mouse, over a div in this case scroll , but i cnt seem to find where i can find the speed, or can make it slower!! im so confused!!

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

    });

The code seems to be just setting the margin directly:

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

That is, it doesn't call any scroll jquery function that could easily be animated. To achieve that you would have to do some rewriting of that code, probably using jquery animate() function with the marginTop css.

The only problem is that the code is called on mousemove, which means that it could easily be called again while the animation is still active. So you will have to come up with some workaround there, like maybe checking first if there is an animation present and aborting it in that case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM