如何设置jquery在页面加载后5秒自动打开,5秒后关闭,我如何做呢?请帮帮我。
我的JS代码:
$(document).ready(function() {
$('#my-welcome-message').firstVisitPopup({
cookieName : 'homepage',
showAgainSelector: '#show-message'
});
});发布于 2015-08-06 18:48:34
你的问题有点不清楚。您想先检查一下cookie吗?如果cookie不存在,请在页面加载5秒后再显示消息吗?然后在5秒后关闭消息?
无论如何,您可以使用Javascript setTimeout在x毫秒后执行代码。
$(document).ready(function() {
var timeOut;
// use setTimeout to call the open function after 5 seconds
timeOut = setTimeout(openMessage, 5000);
function openMessage() {
// your code to display message
// the setTimeout again to run the close function in 5 seconds
timeOut = setTimeout(closeMessage, 5000);
};
function closeMessage() {
// your code to close the message
}
});这应该会给你指明正确的方向。如果你澄清你的帖子,我也许能帮上进一步的忙。
https://stackoverflow.com/questions/31862708
复制相似问题