怎么用js做出,点击一个按钮,弹出一个遮罩层,5秒后自己关闭.的效果

如题所述

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#cover{
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: rgba(0,0,0,0.3);
display:none;
z-index:1000;
}
</style>
</head>
<body>

<button>这是一个按钮</button>
<div id="cover">这是一个遮罩</div>
<script>
var btn=document.getElementsByTagName('button')[0];
btn.addEventListener('click',function(){
var cover=document.getElementById('cover');
cover.style.display='block';
setTimeout(function(){
cover.style.display='none';
},5000)
})

</script>
</body>
</html>

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答