jCarouselLite 重置自动滚动间隔
如何在某些事件发生后重置 jCarouselLite 轮播上的自动滚动间隔,以便它让您可以查看整个时间间隔的内容,无论您单击“下一个”或“上一个”时计时器距离多远?现在,如果我在 9 秒后单击下一个或上一个,它会在 1 秒后再次滚动。
在 jCarouselLite 源代码第 274-277 行中自动滚动是使用setInterval
实现的。我知道如果您有 setInterval 返回的 ID,则可以使用clearInterval,但除了修改源代码之外我没有其他方法,而且我不想这样做。
有什么想法吗?谢谢!
How can I reset the auto-scroll interval on my jCarouselLite carousel after some event so that it lets you look at the content for the full interval, regardless of how far along the timer was when you clicked next or previous? Right now, if I click next or previous after 9 seconds, it scrolls again after 1 second.
In the jCarouselLite source code on lines 274-277 is where the auto-scroll is implemented using setInterval
. I know you can use clearInterval
if you have the ID returned by setInterval, but there isn't one I can get outside of modifying the source code, and I don't want to do that.
Any ideas? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
jCarouselLite 本身没有提供任何简单的方法来停止自动滚动,这是一个更容易的问题,然后做你想要的事情(?我理解正确吗:你只是希望自动滚动在单击时暂时停止,然后继续)
Hacky + 完全停止自动滚动的潜在错误方法
真正的解决方案
由于我们无法让 jCarouselLite 自行执行此操作,因此我们自己模拟
auto
行为。jCarouselLite itself doesn't provide any easy way to stop the auto-scrolling, which is an easier problem then do what you seem to want (?did I understand this right: You just want the autoscroll to temporarily stop on click and then continue)
Hacky + potentially buggy way to stop the autoscroll altogether
Real solution
As we can't get jCarouselLite to do this on its own we simulate the
auto
behavior ourself.这是一个内置鼠标悬停暂停的版本。效果很好。
http://github.com/cheald/jcarousel-lite
Here's a version with a pause on mouseover built-in. Works nicely.
http://github.com/cheald/jcarousel-lite
这些答案都不是我想要的,但这就是当我谷歌“jcarousellite重置计时器”时出现的结果,因此对于下一个人来说:
,这就是我整理的对我有用的内容:
只需将其与当前的 jCarouselLite 脚本交换并以相同的方式使用它。
None of these answers were what I was looking for, but this is what comes up when I Google 'jcarousellite reset timer', so for the next person looking to:
Then this is what I put together that works for me:
Just swap it out with your current jCarouselLite script and use it just the same.
如果您能够/有权更改插件代码:
添加一个变量以将间隔 ID 保存到插件默认值中
搜索:
获取此处执行的代码并用它创建一个内部函数,如下所示:
现在只需将间隔保存到您的插件中即可。定义的变量,但首先清除它:
在插件中搜索
go()
函数并添加一个runAuto()
,因此每次调用函数go时都会重置间隔。当然,您还必须将
runAuto()
调用添加到if(o.auto)
,以便间隔首先开始。If you are able/authorized to change the plugin code:
Add a variable to save the interval id to the plugins defaults
Search for:
Take the code which is executed here and make an internal function with it like:
Now just save the interval to your defined variable but clear it first:
Search for the
go()
function in the plugin and add arunAuto()
, so each time the function go is called it resets the interval.Of course you must also add the
runAuto()
call toif(o.auto)
so the interval starts at first.