【发布时间】:2019-05-20 22:45:04
【问题描述】:
我有一个画廊,它会向用户展示 5 到 5 秒的图片。
function slideSwitch() {
var current = $('#slideshow .active');
current.removeClass('active');
if (current.next().length) {
current.next().addClass('active');
myInterval = setTimeout(slideSwitch, 5000);
bar();
}
}
我想在用户点击并按住 div 持有人的点击时暂停超时。 比如超时是3秒,如果用户点击并按住持有人的div我想在3秒内停止直到保持结束,然后再到4和5秒再次调用该函数。
我看到了这个函数,但我不知道如何在我的 slideSwitch() 中添加它。有什么想法吗?
selector.addEventListener('mousedown', function(event) {
// simulating hold event
setTimeout(function() {
// You are now in a `hold` state, you can do whatever you like!
}, 500);
}
【问题讨论】:
-
你是在尝试实现
clearTimeout&然后打电话重启超时吗? -
@JO3-W3B-D3V 我想在用户单击并按住时暂停超时,而不是清除它并重新启动。
-
您不能暂停计时器 - 只能停止并重新启动。
-
你不能暂停超时但你可以重复它,检查像这样stackoverflow.com/a/29497630/2630817
-
This 可能会帮助你:)
标签: javascript jquery