如何重新启动jquery中的setInterval,以便当用户点击计数器时重新启动
How to restart the setInterval in jquery so that when the user Click the counter restarts?
如何重新启动jquery中的setInterval,以便当用户点击计数器时重新启动?
所以我创建了一个选项卡部分,以便它将循环到下一个选项卡后12秒。然而,我想重新启动时间,如果用户单击所需的选项卡,以便用户获得一个新的12秒。
我是jquery的新手,所以请详细解释。多谢。
$("li.tab").click(function () {
$("li.tab").removeClass("select");
$(".featured_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).fadeIn(1600); //Fade in the active ID content
$(this).addClass("select");
});
var refreshIntervalId = setInterval(function () {
var lastChild = $('li.select').is(':last-child');
if (lastChild) {
$('li.tab').removeClass('select ')
$("li.tab:first").addClass('select ');
return false;
} else {
$("li.select").removeClass('select').next().addClass('select');
return false;
}
}, 12000);
//Stop
clearInterval(refreshIntervalId);
//Start again
setInterval(function () {
...
}, 12000)
使用clearInterval
:
$("li.tab").click(function () {
// ...
refreshIntervalId = clearInterval(refreshIntervalId);
// setInterval again to re-start the 'timer'
// ...
});
相关文章:
- 当我在重新启动cordova应用程序后尝试添加更多数据时,lokijs会丢失数据库和收集中的数据
- 重新启动jquery脚本后,角度停止工作
- Chrome内容脚本制作cookie;chrome重新启动时,cookie会被删除.如何使其稳定
- preventDefault之后的重新启动事件
- WebStorm,使用Node Supervisor(因此不必在每次代码更改后重新启动)
- 重新启动游戏jQuery功能不工作
- Web服务器意外退出,正在重新启动新实例
- 在变量中保存值的最佳方法是在应用程序关闭后使用,然后使用apachecordova在android中重新启动
- 重新启动画布 JavaScript
- 事件侦听器,用于完全关闭后重新启动的应用程序
- Node SocketIO以编程方式强制在损坏的套接字上重新启动
- 服务器重新启动后javascript不工作
- 当滚动到指定的位置时,启动功能,如何重置它并重新启动,如果我们再次回到这个位置
- Gulp Concat+Browsesync重新启动
- 在 javaScript 中重新启动 setInterval
- 重新启动/刷新时在Google Maps API上保存标记,之后's已被用户拖动.下面的
- 从用户离开页面时的位置重新启动计时器
- 如何重新启动jquery中的setInterval,以便当用户点击计数器时重新启动
- Bot必须重新启动才能将用户输入传递给请求函数
- 重新启动用户定义的jquery函数来调整页面大小