jquery滚动速度?
问题描述:
这是一个脚本,我从互联网上得到的,它完美的作品,它是什么反效果自动滚动鼠标的移动,在这种情况下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 */
});
});
答
代码似乎是只设置直接余量:
marginTop: ' - ' + this.totScroll *(Math.max(e.pageY-this.pos.top,0)/ this.height)+'px'
也就是说,它不会调用任何可以轻松动画的滚动jquery函数。为了达到这个目的,你必须重写那段代码,可能会使用带有marginTop css的jquery animate()函数。
唯一的问题是,代码在mousemove上调用,这意味着它可以很容易地在动画仍然活动时再次调用。因此,您必须在那里提出一些解决方法,比如可能首先检查是否存在动画并在此情况下中止它。