<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>延迟下拉菜单</title>
</head>
<style>
ul{
border:1px solid red;
}
ul>li{
border: 1px solid yellow;
margin-bottom: 5px;
}
ul>li h3:hover{
cursor: pointer;
}
ul>li:last-child{
margin-bottom: 0;
}
.d1,.d3{
height: 100px;
overflow: hidden;
background-color: pink;
}
.d2{
height: 100px;
overflow: hidden;
background-color: blanchedalmond;
}
.demo1{
overflow: hidden;
}
@keyframes demo_1 {
0%{
height: 100px;
}
100%{
height: 0;
}
}
@keyframes demo_2 {
0%{
height: 0;
}
100%{
height: 100px;
}
}
</style>
<body>
<ul>
<li>
<h3 οnclick="isShow()">111</h3>
<div class="d1">demo_111</div>
</li>
<li>
<h3 οnclick="isShow()">222</h3>
<div class="d2">demo_222</div>
</li>
<li>
<h3 οnclick="isShow()">333</h3>
<div class="d3">demo_333</div>
</li>
</ul>
</body>
<script>
function isShow(){
var lastChild = event.target.parentNode.children[event.target.parentNode.children.length - 1];
lastChild.classList.toggle("demo1");
var hasClass = lastChild.classList.contains("demo1");
if(hasClass){
lastChild.style.animation = "demo_1 0.5s linear";
lastChild.style.height = "0";
}else{
lastChild.classList.removeClass = "demo1";
lastChild.style.animation = "demo_2 0.5s linear";
lastChild.style.height = "100px";
}
}
</script>
</html>
原生js写jQuery延迟下拉菜单
最新推荐文章于 2021-06-03 18:39:31 发布