菜单交互(menu interaction)
程序员文章站
2022-04-03 23:20:31
...
更多有趣示例 尽在 小红砖社区
示例
代码
HTML
<div class="widget">
<div class="menu">
<div class="toggle">
<i></i>
<i></i>
</div>
<ul class="list">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</div>
<a href="https://dribbble.com/shots/7197834-Menu-Interaction-Concept" target="_blank" class="dribbble">
<img src="https://dribbble.com/assets/logo-small-2x-9fe74d2ad7b25fba0f50168523c15fda4c35534f9ea0b1011179275383035439.png" alt="">
</a>
CSS
body {
width: 100%;
height: 100vh;
padding: 0;
margin: 0;
background-color: #9CB46D;
display: flex;
align-items: center;
justify-content: center;
}
.widget {
width: 288px;
height: 200px;
display: flex;
justify-content: flex-end;
border-radius: 10px;
background-color: #FFF;
&.active {
.menu {
width: 344px;
.toggle {
right: 296px;
i {
width: 8px;
transition: width 400ms cubic-bezier(.6,0,.45,.99),
transform 1000ms cubic-bezier(.6,0,.45,.99) 300ms,
top 200ms cubic-bezier(.6,0,.45,.99) 200ms,
bottom 200ms cubic-bezier(.6,0,.45,.99) 200ms;
&:first-of-type {
top: 19px;
transform: rotate(45deg) translate(-1px, -2px);
}
&:last-of-type {
bottom: 19px;
transform: rotate(-45deg) translate(-1px, 2px);
}
}
}
.list {
visibility: visible;
flex-direction: row-reverse;
li {
transform: scale(1);
}
}
}
}
.menu {
width: 56px;
height: 56px;
display: flex;
align-items: center;
justify-content: center;
position: absolute;
border-radius: 100px;
background-color: #4C5042;
transform: translate(28px, -50%);
box-shadow: 0px 10px 30px -15px rgba(0, 0, 0, 0.7);
transition: 650ms cubic-bezier(.79,0,.22,1);
.toggle {
width: 40px;
height: 40px;
right: 8px;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
position: absolute;
border-radius: 100px;
cursor: pointer;
z-index: 100;
background-color: #4C5042;
transition: 600ms cubic-bezier(.79,0,.22,1);
&:hover {
background-color: #3C4134;
}
i {
width: 12px;
height: 2px;
position: absolute;
display: flex;
border-radius: 100px;
background-color: #FFF;
transition: width 400ms cubic-bezier(.6,0,.45,.99),
transform 600ms cubic-bezier(.6,0,.45,.99),
top 600ms cubic-bezier(.6,0,.45,.99) 600ms,
bottom 600ms cubic-bezier(.6,0,.45,.99) 600ms;
&:first-of-type {
top: 16px;
}
&:last-of-type {
bottom: 16px;
}
}
}
.list {
flex-direction: row;
margin: 0;
right: 8px;
display: flex;
align-items: center;
justify-content: center;
visibility: hidden;
position: absolute;
li {
width: 40px;
height: 40px;
margin-left: 8px;
list-style: none;
border-radius: 100px;
background-color: #73776C;
transform: scale(0);
transition: 300ms cubic-bezier(.37,.01,.43,1.3);
transition-delay: 300ms;
@for $i from 1 through 6{
&:nth-child(#{$i}){
transition-delay: $i * 50ms;
}
}
}
}
}
}
.dribbble {
position: fixed;
display: block;
right: 24px;
bottom: 24px;
img {
display: block;
width: 76px;
}
}
JS
let widget = document.querySelector('.widget')
let toggle = document.querySelector('.toggle')
toggle.addEventListener('click', () => {
widget.classList.toggle('active')
})
上一篇: 苹果Mac虚拟机装Windows哪家强?