本文實例講述了JS實現可自定義大小,可雙擊關閉的彈出層效果。分享給大家供大家參考。具體如下:
這是一款JS彈出層,可自定義大小,雙擊關閉層,可以彈出500,300、500,500大小的窗口,窗口彈出后,在彈出窗口內雙擊即可關閉鼠標。我覺得挺不錯的效果,可以學習到不少的JS知識。
運行效果截圖如下:

在線演示地址如下:
http://demo.VeVB.COm/js/2015/js-define-close-able-alert-dlg-demo/
具體代碼如下:
<!DOCTYPE html><html><head><title>JS彈出層</title><style>body {margin:0px}#Loading {position:absolute;z-index:10;left:10px;top:10px;border:1px #666666 solid;background:#eeeeee;width:10px;height:10px}</style><script LANGUAGE="JavaScript"><!--function $(){return document.getElementById?document.getElementById(arguments[0]):eval(arguments[0]);}var OverH,OverW,ChangeDesc,ChangeH=50,ChangeW=50;function OpenDiv(_Dw,_Dh,_Desc) {$("Loading").innerHTML="";OverH=_Dh;OverW=_Dw;ChangeDesc=_Desc;$("Loading").style.display='';if(_Dw>_Dh){ChangeH=Math.ceil((_Dh-10)/((_Dw-10)/50))}else if(_Dw<_Dh){ChangeW=Math.ceil((_Dw-10)/((_Dh-10)/50))}$("Loading").style.top=(document.documentElement.clientHeight-10)/2+"px";$("Loading").style.left=(document.documentElement.clientWidth-10)/2+"px";OpenNow()}var Nw=10,Nh=10;function OpenNow() {if (Nw>OverW-ChangeW)ChangeW=2;if (Nh>OverH-ChangeH)ChangeH=2;Nw=Nw+ChangeW;Nh=Nh+ChangeH;if(OverW>Nw||OverH>Nh) {if(OverW>Nw) {$("Loading").style.width=Nw+"px";$("Loading").style.left=(document.documentElement.clientWidth-Nw)/2+"px";}if(OverH>Nh) {$("Loading").style.height=Nh+"px";$("Loading").style.top=(document.documentElement.clientHeight-Nh)/2+"px"}window.setTimeout("OpenNow()",10)}else{Nw=10;Nh=10;ChangeH=50;ChangeW=50;$("Loading").innerHTML=ChangeDesc;}}//--></script></head><body><a href="javascript:OpenDiv(500,300,'層1<br>雙擊關閉')">層1 500*300</a><br><br><a href="javascript:OpenDiv(500,200,'層2<br>雙擊關閉')">層2 500*200</a><br><br><a href="javascript:OpenDiv(200,500,'層3<br>雙擊關閉')">層3 200*500</a><br><br><a href="javascript:OpenDiv(500,500,'層4<br>雙擊關閉')">層4 500*500</a><a href="javascript:OpenDiv(500,500,'層5<br>雙擊關閉')">層5 500*500</a><div id="Loading" style="display:none" ondblclick="this.style.display='none'"></div></body></html>希望本文所述對大家的JavaScript程序設計有所幫助。
新聞熱點
疑難解答