2013-04-10 61 views
-2
$(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(1000);  
     $('#mask').fadeTo("slow",0.8); 

     //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(2000);  

    //if close button is clicked 
    $('.window .close').click(function (e) { 
     //Cancel the link behavior 
     e.preventDefault(); 

     $('#mask').hide(); 
     $('.window').hide(); 
    });  

    //if mask is clicked 
    $('#mask').click(function() { 
     $(this).hide(); 
     $('.window').hide(); 
    });  

}); 

我用這個代碼的onload彈出框的瀏覽器,但是當我刷新我的瀏覽器每次表演這個彈出框不爲1的時候,請告訴我正確的方式。onload事件彈出窗口中打開每一次當我刷新

+0

這不是Queness的jQuery的模態窗口腳本? – 2013-04-10 04:33:09

+0

不,這只是簡單的模式彈出框。 – 2013-04-10 04:34:15

+0

@AnmolRatanMohla [代碼太類似](http://www.queness.com/post/77/simple-jquery-modal-window-tutorial)是別的東西..相同的變量名稱,相同的值.. – Daedalus 2013-04-10 04:38:15

回答

0

您需要使用某種cookie來第一次設置。因此,將所有內容都包含在一個函數中,例如showPopup();,並在添加jQuery.cookie插件後以此方式調用代碼。

$(document).ready(function() { 
    if (!$.cookie('showPopup')) { 
    showPopup(); 
    $.cookie('showPopup', 'yes') 
    } 
}); 
+0

請給我一個例子。 – 2013-04-10 04:36:21

+0

@AnmolRatanMohla我給你的代碼! – 2013-04-10 04:38:21

+0

是的,你是對的普拉文先生,但告訴我在哪裏添加我的id或類像:#dialog – 2013-04-10 04:39:28

0

使用此事件設置任何變量,並在代碼中使用它。

window.onunload = function(){ 
alert("unload event detected!"); 

}

+0

我真遺憾,但是,我的客戶給我這個代碼並要求我使用這段代碼。 – 2013-04-10 04:52:25

+0

請準備好我上面提到的代碼,如果你添加了一些東西,給我完整的代碼。 – 2013-04-10 04:53:53

+0

請幫助我。 – 2013-04-10 04:54:13