只是我想从调用它停止后像5秒特定时间的函数。
我无法找到一个方法来做到这一点,可以有人帮助我
function popUp() {
// Do some Thing
});
popUp();
// how to stop popUp() after calling it after 5 seconds from calling it??
您可以使用setTimout
设定的时间量之后运行的功能。例如:
setTimeout(hidePopup, 5000);
将在5秒钟(5000毫秒)后运行以下功能:
function hidePopup() {
// Do the opposite
}
只需使用return语句:
function popUp() {
// Do some Thing
//Timer simulator
for (i = 0; i < 100; i++) {
if (i == 99) return
}
});
怎么样,你打电话给你的函数,然后在5秒后叫你的setTimeout函数内部改变显示为“无”,就像这样:
function popUp() {
// Do some Thing
// SetTimeout to change display to none
setTimeout(function () {
document.getElementById('div-id').style.display = "none";
}, 5000);
});
popUp();