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
2 Answers
Reset to default 2Wrap 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/