I want to make this modal window appear after 10seconds when the page has loaded..tnx everyone
$(document).ready(function() {
var id = "#dialog";
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set heigth and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});
//transition effect
$('#mask').fadeIn('fast');
$('#mask').fadeTo('fast');
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
开发者_开发知识库//Set the popup window to center
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);
//transition effect
$(id).fadeIn('fast');
//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
$('#mask').fadeOut();
$('.window').fadeOut();
});
//if mask is clicked
$('#mask').click(function () {
$(this).unhide();
$('.window').unhide();
});
});
Hide the modal window when document is loaded, using the setTimeout() method show, the div
Check this code.
$(document).ready(
function(){
$("#dialog").hide();
setTimeout(function(){
$("#dialog").show();
}, 10 * 1000);
}
);
To execute a function after a delay, you can use window.setTimeout(fun, milliseconds)
. It's common to use this with anonymous functions. For example, if you want to do something 10 seconds after the page loads:
$(function()
{
setTimeout(function()
{
alert("Something");
}, 10 * 1000);
});
Regarding the code above just paste
//set a delay on load
$('#mask').delay(5000);
Right after the below code
//Set heigth and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});
After that paste
//set a delay on load
$(id).delay(5000);
Right before
//transition effect
$(id).fadeIn(2000);
I hope this helps.
精彩评论