Skip to content

Instantly share code, notes, and snippets.

@sunzsh
Created October 15, 2022 14:01
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sunzsh/f32ad1c13fd78ee26d779c9d30c56834 to your computer and use it in GitHub Desktop.
Save sunzsh/f32ad1c13fd78ee26d779c9d30c56834 to your computer and use it in GitHub Desktop.
全屏折叠面板demo
<!DOCTYPE html>
<html lang="en">
<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>
body, html {
height: 100%;
margin: 0;
}
.wrapper {
display: flex;
flex-direction: column;
height: 100%;
overflow: hidden;
background-color: linen;
}
.item {
text-align: center;
flex-grow: 0;
transition: flex-grow .3s;
position: relative;
}
.title {
background-color: rgb(150, 181, 183);
color: rgb(4, 43, 46);
height: 44px;
line-height: 44px;
border-top:rgb(125, 157, 160) solid 1px;
}
.active {
flex-grow: 1;
}
.content {
position: absolute;
top: 44px;
left: 0;
width: 100%;
overflow: auto;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="item">
<div class="title">111</div>
<div class="content">
asdkfjasldfkjas;ldf
asdflkajsdfl
</div>
</div>
<div class="item active">
<div class="title">222</div>
<div class="content">
1231
</div>
</div>
<div class="item">
<div class="title">333</div>
<div class="content">
43laksdjflaskdj
</div>
</div>
</div>
<script>
const items = document.querySelectorAll('.title');
items.forEach(item => {
item.addEventListener('click', () => {
document.querySelector('.active').classList.remove('active');
item.parentElement.classList.toggle('active');
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment