2011-03-11 42 views
0
$(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(); 
}); 


}); 
+0

你能描述你想從這個代碼做什麼呢? – 2011-03-11 03:28:19

+0

這個腳本在頁面加載時會自動啓動模態對話框..但是我的問題是我想要在20秒的時間內(例如20秒)啓動模態對話框。 – ton 2011-03-11 03:32:56

+0

爲什麼你不使用jquery對話框,並在可以通過setTimeout調用的函數中調用.dialog(「open」)方法 – 2011-03-11 03:59:21

回答

0

爲什麼你需要setTimeout?你想達到什麼目的?如果您想獲得有用的回覆,則需要更多信息。

將您在$(document).ready中的所有內容添加到另一個函數showDialog()中。 然後在$(doc).ready中加入:

var myTimeout = setTimeout(showDialog,20000);

+0

我想在10秒後啓動模態窗口請求報價表單。 – ton 2011-03-11 03:39:37

0

這裏有一種方法:

$(document).ready(function(){ 

    (function delayedModal(){ 
    var id = '#dialog'; 
    // ...snip... 
    var timer = setTimeout(function(){ 
     $(id).fadeIn('fast'); 
    },20000); 
    }()); 

    // ...snip... 

});