<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
.body {
width: 100%;
height: 300px;
background-color: black;
position: fixed;
z-index: 999999;
border-top: solid 1px #ccc;
bottom: 0;
-webkit-transition: .3s;
-webkit-transform: translateY(400px)
}
.active {
-webkit-transform: translateY(0);
}
</style>
<body>
<button class="btn">按钮</button>
<div class="body">
</div>
<script>
var btn = document.querySelector(".btn");
var bbody = document.querySelector(".body");
btn.addEventListener("click", function (e) {
bbody.classList.add('active');
e.stopPropagation()
});
btn.addEventListener('click', function (e) {
e.stopPropagation()
});
bbody.addEventListener('click', function (e) {
e.stopPropagation()
});
document.addEventListener('click', function (e) {
bbody.classList.remove('active')
})
</script>
</body>
</html>
js点击按钮弹出盒子,点击盒子以外的地方隐藏盒子
于 2024-06-01 15:17:49 首次发布