简体   繁体   English

jQuery的滚动速度?

[英]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!! 这是我从互联网上获得的一个脚本,它运行完美,它在鼠标移动时自动scroll ,在这种情况下scroll到div上,但我似乎并没有找到可以找到速度的地方,或可以使其变慢! 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' 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. 也就是说,它不会调用任何可以轻松动画化的滚动jquery函数。 To achieve that you would have to do some rewriting of that code, probably using jquery animate() function with the marginTop css. 为了实现这一点,您可能必须重写一些代码,可能将jquery animate()函数与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. 唯一的问题是在mousemove上调用了代码,这意味着可以在动画仍处于活动状态时轻松地再次调用该代码。 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. 因此,您将不得不在此处提出一些解决方法,例如可能首先检查是否存在动画,并在这种情况下中止动画。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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