我有一个 cookie 弹出窗口,当页面在 5 秒后加载时我需要淡入,如果单击弹出窗口,它将打开并重置计时器。这是我到目前为止所拥有的。
function cookiePopup(){
var $cookie_popup = $("#cookie_popup");
words = $cookie_popup.children('p').text().split(' ').length;
alert(words);
$cookie_popup.fadeIn(200).delay(words*200+3000).fadeOut(function()
{$(this).remove();
});
$cookie_popup.children("#cookie_close").on("click",function(){
$cookie_popup.hide().remove;
});
}
最佳答案
伪代码:
var timeout = setTimeout( createPopup, 5000 );
function createPopup() {
clearTimeout( timeout );
// .. popup creation code ..
}
something.onclick = createPopup;
关于javascript - 如何在元素上设置计时器,以便在单击元素打开时淡出并重置计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24328699/