网页蒙砂效果2

本文介绍了一种使用JavaScript来控制网页元素显示与隐藏的方法。通过两个函数my_xianshi和my_yincang实现了指定div的显示与隐藏效果,并通过创建背景遮罩增强了用户体验。文中展示了具体的JavaScript代码及HTML结构。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript"> 
 


function my_yincang(check_div){
var mydiv=document.getElementById(check_div);
mydiv.style.display="none";
var bw=document.getElementById("my_bgDiv");
document.body.removeChild(bw);


}
function my_xianshi(play){
var mydiv=document.getElementById(play);
mydiv.style.display="";
//mydiv.style.top=(document.body.offsetHeight-350)/2+"px";
//mydiv.style.top=(document.body.clientHeight-350)/2+document.body.scrollTop+"px";
mydiv.style.top=document.documentElement.scrollTop+100+"px";
mydiv.style.left=(document.body.clientWidth-700)/2+"px";
var My_bgObj=document.createElement("div");
            My_bgObj.setAttribute('id','my_bgDiv');
            My_bgObj.style.position="absolute";
            My_bgObj.style.top="0";
            My_bgObj.style.background="#777";
            My_bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
            My_bgObj.style.opacity="0.6";
            My_bgObj.style.left="0";
My_bgObj.style.zIndex=2;
            My_bgObj.style.width=document.body.clientWidth+"px";
            My_bgObj.style.height=document.body.clientHeight+"px";
            document.body.appendChild(My_bgObj);
}
</SCRIPT>
 
 
</head>
<body>
<input type="button" value="显示" onClick="my_xianshi('hhh')"/>
 <input type="button" value="隐藏" onClick="my_yincang('hhh')"/>
 
 <div style="background-color:#0033FF; width:500px; height:500px; z-index:10; display:none;position: absolute;" id="hhh"></div>


</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值