最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Show popup after some seconds... - Stack Overflow

programmeradmin2浏览0评论

I am using a simple popup for my site , Here's the below code, I want to show the popup after some interval of seconds,

Please help

<script type='text/javascript'>

$(function(){
var overlay = $('<div id="overlay"></div>');
overlay.show();
overlay.appendTo(document.body);

$('.popup').show();
$('.close').click(function(){
$('.popup').hide();
overlay.appendTo(document.body).remove();

return false;
});

$('.x').click(function(){
$('.popup').hide();
overlay.appendTo(document.body).remove();
return false;
});
});
</script>

I am using a simple popup for my site , Here's the below code, I want to show the popup after some interval of seconds,

Please help

<script type='text/javascript'>

$(function(){
var overlay = $('<div id="overlay"></div>');
overlay.show();
overlay.appendTo(document.body);

$('.popup').show();
$('.close').click(function(){
$('.popup').hide();
overlay.appendTo(document.body).remove();

return false;
});

$('.x').click(function(){
$('.popup').hide();
overlay.appendTo(document.body).remove();
return false;
});
});
</script>
Share Improve this question asked Apr 2, 2015 at 20:05 APEXAPEX 471 gold badge2 silver badges13 bronze badges 1
  • 1 What you're probably looking for is javascript's setTimeout() function. As a friendly aside, you may want to get into the habit of formatting your code with proper indents - it's hard to read the structure as it is. – CodeMoose Commented Apr 2, 2015 at 21:03
Add a ment  | 

2 Answers 2

Reset to default 2

Wrap the line that shows your popup in a setTimeout like this:

setTimeout(function(){
    $('.popup').show();
}, 5000);

You can use delay() method, e.g.:

$('.popup').delay(3000).fadeIn(100);

demo: http://jsfiddle/54pzpfp1/

发布评论

评论列表(0)

  1. 暂无评论