<!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>
#div1 {
width: 200px;
height: 40px;
background: rgb(184, 173, 243);
}
.list {
max-height: 0;
width: 200px;
padding: 0;
margin: 0;
overflow: hidden;
transition: max-height .5s;
background: rgba(173, 202, 221, 0.3);
}
.checked~.list {
max-height: 1000px;
}
</style>
<body>
<script>
window.onload = function () {
var div1 = document.getElementById('div1')
div1.onclick = toggleShow
}
var checked = false
function toggleShow() {
checked = !checked
if (checked) {
div1.setAttribute('class', 'checked')
} else {
div1.setAttribute('class', '')
}
}
</script>
<div id="div1">菜单</div>
<ul class="list">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</body>
</html>
css+js实现下拉菜单过渡效果
最新推荐文章于 2022-10-15 00:26:11 发布