jQuery-滚动到和串行滚动不一起工作
我已经测试了scrollTo()插件,但是我需要一种停止滚动动画的方法,所以我正在查看serialScroll() 下面是我在scrollTo中使用的内容:jQuery-滚动到和串行滚动不一起工作,jquery,plugins,scroll,Jquery,Plugins,Scroll,我已经测试了scrollTo()插件,但是我需要一种停止滚动动画的方法,所以我正在查看serialScroll() 下面是我在scrollTo中使用的内容: $('#scroller').scrollTo('1000px', 3000); 我的问题是,我如何用serialScroll做同样的事情?我不能让它以与scrollTo相同的方式工作,这不是它应该做的吗,只是添加了大量的额外选项 当SerialScroll绑定多个事件(包括stop事件)时,您可以使用toggle根据单击启动/停止滚动:
$('#scroller').scrollTo('1000px', 3000);
我的问题是,我如何用serialScroll做同样的事情?我不能让它以与scrollTo相同的方式工作,这不是它应该做的吗,只是添加了大量的额外选项 当
SerialScroll
绑定多个事件(包括stop
事件)时,您可以使用toggle
根据单击启动/停止滚动:
// setup serialScroll to scroll the images in the 'serialScroll-test' div along
// the y-axis.
$('#serialScroll-test').serialScroll({items: 'img', duration: 2000, axis: 'y', interval: 1, force: true});
// since we used the "force: true" option to auto-start the animation we use
// "stop" as the first function to toggle and "start" second.
$('#serialScroll-test').toggle(function(){
$('#serialScroll-test').trigger('stop.serialScroll');
}, function() {
$('#serialScroll-test').trigger('start.serialScroll');
});
在以下HTML上:
<div id="serialScroll-test" style="float: left; width: 600px; height: 333px; overflow: hidden;">
<img class="scrollable" src="http://farm4.static.flickr.com/3489/3849497254_4722754872.jpg" alt="IMG_7997" />
<img class="scrollable" src="http://farm3.static.flickr.com/2487/3867263002_f6b368d983.jpg" alt="IMG_8005" />
<img class="scrollable" src="http://farm3.static.flickr.com/2528/4043006363_81931d7985.jpg" alt="IMG_2235" />
</div>
注意触发器中的附加stop()
。根据我上面发布的代码,您可以将toggle()
函数更改为:
$('#serialScroll-test').toggle(function(){
$('#serialScroll-test').stop().trigger('stop.serialScroll');
}, function() {
$('#serialScroll-test').stop().trigger('start.serialScroll');
});
产生期望的效果。()我之所以想这样做,是因为我需要使用单击事件停止动画。因此,我想使用.stop()函数来停止滚动动画,但scrollTo似乎不支持这一点,这就是为什么我希望使用serialScroll。那么,在动画期间没有办法停止滚动动画?与标准jQuery.stop()函数停止动画的方式类似?@Nic找到了如何让动画按需要工作:答案已更新。
$('#serialScroll-test').toggle(function(){
$('#serialScroll-test').stop().trigger('stop.serialScroll');
}, function() {
$('#serialScroll-test').stop().trigger('start.serialScroll');
});