[英]jquery scroll speed?
这是我从互联网上获得的一个脚本,它运行完美,它在鼠标移动时自动scroll
,在这种情况下scroll
到div上,但我似乎并没有找到可以找到速度的地方,或可以使其变慢! 我很混乱!!
$("#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函数。 为了实现这一点,您可能必须重写一些代码,可能将jquery animate()函数与marginTop CSS一起使用。
唯一的问题是在mousemove上调用了代码,这意味着可以在动画仍处于活动状态时轻松地再次调用该代码。 因此,您将不得不在此处提出一些解决方法,例如可能首先检查是否存在动画,并在这种情况下中止动画。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.