javascript彈出一個層并增加一個覆蓋層
更新時間:2008年10月10日 23:14:41 作者:
彈出一個層的js代碼,比較不錯
復(fù)制代碼 代碼如下:
<!--內(nèi)容層-->
<div id="ShopConfirmLayer" style="position:absolute;top:300px;left:100px;z-index:900;border:1px red solid;width:500px;display:none;">
<input name="button1" value="關(guān)閉" type="button" onclick="CloseShopConfirm()"/>
</div>
<!--覆蓋層-->
<div id="webBgLayer" style="position:absolute;top:0px;left:0px;z-index:899;background-color:#ccc;height:100%;width:100%;display:none;-moz-opacity:0.5;filter:alpha(opacity=50);"></div>
<script type="text/javascript">
function ShopConfirm(str){
var ShopConfirmLayer=document.getElementById("ShopConfirmLayer");
var webBgLayer=document.getElementById("webBgLayer");
ShopConfirmLayer.innerHTML=str;
ShopConfirmLayer.style.display="";
ShopConfirmLayer.style.left=parseInt((document.documentElement.scrollWidth-ShopConfirmLayer.offsetWidth)/2)+document.documentElement.scrollLeft+"px";
ShopConfirmLayer.style.top=Math.abs(parseInt((document.documentElement.clientHeight-ShopConfirmLayer.offsetHeight)/2))+document.documentElement.scrollTop+"px";
webBgLayer.style.display="";
webBgLayer.style.height=document.documentElement.scrollHeight+"px";
}
function CloseShopConfirm(){
var ShopConfirmLayer=document.getElementById("ShopConfirmLayer");
var webBgLayer=document.getElementById("webBgLayer");
ShopConfirmLayer.style.display="none";
webBgLayer.style.display="none";
}
</script>
注意上面的代碼頭部DTD應(yīng)該是這樣:
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
相關(guān)文章
uniapp頁面?zhèn)鲄⒌娜N方式實例總結(jié)
在進行頁面的跳轉(zhuǎn)的時候,往往需要我們將一些參數(shù)攜帶著傳遞過去這里的class樣式,下面這篇文章主要給大家介紹了關(guān)于uniapp頁面?zhèn)鲄⒌娜N方式,需要的朋友可以參考下2022-11-11JS實現(xiàn)顏色的10進制轉(zhuǎn)化成rgba格式的方法
這篇文章主要介紹了JS實現(xiàn)顏色的10進制轉(zhuǎn)化成rgba格式的方法,涉及javascript針對顏色數(shù)值轉(zhuǎn)換的相關(guān)運算操作技巧,需要的朋友可以參考下2017-09-09js實現(xiàn)百度聯(lián)盟中一款不錯的圖片切換效果完整實例
這篇文章主要介紹了js實現(xiàn)百度聯(lián)盟中一款不錯的圖片切換效果的方法,以完整實例形式分析了javascript操作圖片切換的技巧,需要的朋友可以參考下2015-03-03