【发布时间】:2023-04-10 03:55:02
【问题描述】:
我正在开发一个圆形汉堡菜单按钮,该按钮在悬停时动画,从中心开始增长,三个条形子 div 居中在父 div 圈内。
父 div 具有固定的定位以启用“增长”效果。三个汉堡菜单行是绝对定位的 div。
当悬停时,通过过渡动画的一切都很好,除了三个子 div 在悬停时从 右下角 和鼠标移出时从 左上角 跳。我试过调整边距、宽度/高度和定位,但我被卡住了。我错过了什么?
.circle-nav {
display: block;
position: fixed;
width: 44px;
height: 44px;
top: 35px;
left: 35px;
color: rgba(255, 255, 255, 0.8);
background-color: rgb(136, 35, 24);
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3), 0 2px 2px rgba(0, 0, 0, 0.05);
-webkit-border-radius: 22px;
-moz-border-radius: 22px;
border-radius: 22px;
transition: width 300ms ease, height 300ms ease, transform 300ms ease, background 300ms ease, border-radius 300ms ease, box-shadow 300ms ease, top 300ms ease, left 300ms ease;
}
.circle-nav:hover {
width: 66px;
height: 66px;
top: 25px;
left: 25px;
background-color: rgb(187, 53, 39);
box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3), 0 8px 6px rgba(0, 0, 0, 0.05);
-webkit-border-radius: 33px;
-moz-border-radius: 33px;
border-radius: 33px;
}
.top-bar,
.mid-bar,
.bot-bar {
width: 22px;
height: 2px;
position: absolute;
left: 11px;
background-color: #fff;
}
.top-bar {
top: 14px;
}
.mid-bar {
top: 21px;
}
.bot-bar {
top: 28px;
}
.circle-nav:hover .top-bar {
top: 24px;
}
.circle-nav:hover .mid-bar {
top: 31px;
}
.circle-nav:hover .bot-bar {
top: 38px;
}
.circle-nav:hover .top-bar,
.circle-nav:hover .mid-bar,
.circle-nav:hover .bot-bar {
left: 22px;
}
<div class="circle-nav">
<div class="top-bar"></div>
<div class="mid-bar"></div>
<div class="bot-bar"></div>
</div>
【问题讨论】:
标签: css css-transitions css-animations