1、先写俩盒子,一个是全屏覆盖的颜色透明点的覆盖框cover,一个是你的弹出框pop_frame
<div id="btn" style="width: 100px;height: 100px;font-size: 24px;line-height: 100px;text-align: center;color: blue;border: 1px solid blue;margin-left: 20px;">click it</div>
<div id="cover"></div>
<div id="pop_frame">你的小舞台</div>
2.css配置,关键是cover配置,俩盒子都先隐藏,如果想弹出框位置自己定可以fixed,cover的高度我设置的100%,也就是body的高度,自己随便设置吧
<style>
#cover{
position: absolute;
top: 0;
background: #777;
opacity: 0.7;
left: 0;
width: 100%;
height: 100%;
filter: progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75);
display: none;
}
#pop_frame{
width: 300px;
height: 50px;
font-size: 24px;
line-height: 50px;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
margin-top: -25px;
margin-left: -150px;
background: orange;
display: none;
}
</style>
3、设置个点击事件就完事了,完美
<script>
var btn=document.querySelector('#btn');
var cover=document.querySelector('#cover');
var pop_frame=document.querySelector('#pop_frame');
btn.addEventListener('click',function () {
cover.style.display='block';
pop_frame.style.display='block';
setTimeout(function () {
cover.style.display='none';
pop_frame.style.display='none';
},5000);
})
</script>