<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#stopBox {
position: relative;
}
#closeBox {
text-align: center;
line-height: 50px;
display: inline-block;
position: absolute;
left: 342px
}
</style>
</head>
<body>
<div class="box" id="stop">
<i id="closeBox">X</i>
</div>
<script>
let stopBox = document.getElementById('stop')
let closeBox = document.getElementById('closeBox')
//给盒子添加css元素
stopBox.style.width = "500px"
stopBox.style.height = "500px"
stopBox.style.backgroundColor = 'red'
stopBox.style.margin = "0 auto"
// 给小盒子添加边框
closeBox.style.width = '50px'
closeBox.style.height = '50px'
closeBox.style.border = '1px solid #000'
// 添加点击事件
closeBox.addEventListener('click', function () {
stopBox.style.display = "none"
// this.style.display = "none" // this指向函数的调用者--closeBox
})
</script>
</body>
</html>
案例--消除图片
最新推荐文章于 2024-07-29 10:53:12 发布