2012-04-17 86 views
0

我想做一個JavaScript彈出白色廣告,然後關閉10秒後,我已經搜索了互聯網的任何事情做到這一點,但我找不到任何東西。Javascript自動關閉彈出窗口10秒後

我不是一個非常過期的JavaScript程序員。

<script type="text/javascript"> 



$(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(); 
    });  


}); 

</script> 

最好的問候,

葉普小號

+0

請格式化你的代碼,使其可讀。 – Jake 2012-04-17 08:04:53

+1

@JeppeS:請花點時間閱讀:http://stackoverflow.com/editing-help和http://sscce.org/ – spender 2012-04-17 08:06:13

+0

您的代碼使用JQuery。一定要包含所需的文件。 – Basilevs 2012-04-17 08:17:13

回答

3

這應該做的伎倆:

setTimeout(function() { 
    $(id).hide(); 
}, 10000); 
+1

與上面一樣,添加'$('#mask')。hide();'以及... – Sriram 2012-04-17 09:26:06