悬停在 div 框上时动画两个元素?
我想制作这个关闭按钮,当我将鼠标悬停在它上面时会执行此动画。一条线必须走到一侧,反之亦然,但我坚持这一点,我不知道是否有解决方案。就像当鼠标进入父(关闭)区域时必须进行 360 度旅行,或者类似的东西,但主要目的是它们两者同时工作,这是我无法实现的。 ´ 预先感谢您<3
#close {
width: 35px;
height: 35px;
display: block;
margin: 0 auto;
box-sizing: border-box;
padding-top: 50px;
}
#close .bar5,
#close .bar6,
#close .bar7 {
width: 35px;
height: 3px;
background-color: black;
margin: 6px 0;
transition: 0s;
}
.bar5:hover {
animation: rota2 1.2s ease-in-out;
}
.bar7:hover {
animation: rota1 1.2s ease-in-out;
}
.bar5 {
-webkit-transform: rotate(-45deg) translate(-6px, 6px);
transform: rotate(-45deg) translate(-6px, 6px);
}
.bar6 {
opacity: 0;
}
.bar7 {
-webkit-transform: rotate(45deg) translate(-6px, -8px);
transform: rotate(45deg) translate(-6px, -8px);
}
@keyframes rota1 {
0% {
-webkit-transform: rotate(45deg)translate(-6px, -8px);
transform: rotate(45deg)translate(-6px, -8px);
}
100% {
-webkit-transform: rotate(-320deg) translate(-6px, -8px);
transform: rotate(-320deg) translate(-6px, -8px);
}
}
@keyframes rota2 {
0% {
-webkit-transform: rotate(-45deg)translate(-6px, 6px);
transform: rotate(-45deg)translate(-6px, 6px);
}
100% {
-webkit-transform: rotate(320deg) translate(-6px, 6px);
transform: rotate(320deg) translate(-6px, 6px);
}
}
<div id="close">
<div class="bar5"></div>
<div class="bar6"></div>
<div class="bar7"></div>
</div>
I want to make this close button that when i hover through it does this animation. One line has to go to one side and viceversa, but I'm stuck with this and i don't know if there is a solution. Its like the have to do a 360deg travel when the mouse enters in the parent (close) aera, or something like that, but the main purpose is that both of them to work at the same tame, the thing that i cant achieve. ´
Thank you in advance <3
#close {
width: 35px;
height: 35px;
display: block;
margin: 0 auto;
box-sizing: border-box;
padding-top: 50px;
}
#close .bar5,
#close .bar6,
#close .bar7 {
width: 35px;
height: 3px;
background-color: black;
margin: 6px 0;
transition: 0s;
}
.bar5:hover {
animation: rota2 1.2s ease-in-out;
}
.bar7:hover {
animation: rota1 1.2s ease-in-out;
}
.bar5 {
-webkit-transform: rotate(-45deg) translate(-6px, 6px);
transform: rotate(-45deg) translate(-6px, 6px);
}
.bar6 {
opacity: 0;
}
.bar7 {
-webkit-transform: rotate(45deg) translate(-6px, -8px);
transform: rotate(45deg) translate(-6px, -8px);
}
@keyframes rota1 {
0% {
-webkit-transform: rotate(45deg)translate(-6px, -8px);
transform: rotate(45deg)translate(-6px, -8px);
}
100% {
-webkit-transform: rotate(-320deg) translate(-6px, -8px);
transform: rotate(-320deg) translate(-6px, -8px);
}
}
@keyframes rota2 {
0% {
-webkit-transform: rotate(-45deg)translate(-6px, 6px);
transform: rotate(-45deg)translate(-6px, 6px);
}
100% {
-webkit-transform: rotate(320deg) translate(-6px, 6px);
transform: rotate(320deg) translate(-6px, 6px);
}
}
<div id="close">
<div class="bar5"></div>
<div class="bar6"></div>
<div class="bar7"></div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
>
选择直接子元素并为其指定效果。我删除了您的填充样式,因为它会使
hover
效果无法按预期工作。You could use the
>
to select immediate child element and assign effect to it.I remove your padding style since it will make the
hover
effect doesn't work as expected.