I have an animation on my site which goes from width: 100px to 800px
when hover on.
我的网站上有一个动画,当它悬停时,从宽度:100px到800px。
But when hover out, it just goes to the normal position with no animation.
但是当它悬停时,它只会进入正常位置而没有动画。
How could I get it so the animation would go back on hover-out the same way it came on hover?
我怎么能得到它所以动画会像悬停时那样重新悬停?
I only found solutions for transitions, but I need it for animation.
我只找到过渡的解决方案,但我需要它用于动画。
<div id="blackbox"/>
<div id="blacktxt">
Navigation
</div>
2 个解决方案
#1
9
Why not use transitions instead of animations? Working jsFiddle
为什么不使用转换而不是动画?工作jsFiddle
#blackbox {
background: black;
width: 100px;
height: 80px;
color: white;
text-align: center;
font-family: Times;
font-size: 20px;
position: fixed;
left: 0px;
bottom: 100px;
opacity: 0.5;
margin-bottom: 10px;
transition: all 2s; /* Add this transition */
}
#blackbox:hover { /* Apply the new design on hover */
opacity: 0.8;
width: 800px;
}
#blacktxt {
margin-top: 10px;
height: 60px;
transition: opacity 0.5s, width 5s;
position: absolute;
font-family: cursive;
cursor: default;
}
#blacktxt:hover {
opacity: 0;
}
#2
0
I wrote the jQuery Reversible plugin for this. Its main advantage over CSS transitions is that it works on IE9 and older browsers.
我为此编写了jQuery Reversible插件。它比CSS过渡的主要优点是它适用于IE9和旧版浏览器。
#1
9
Why not use transitions instead of animations? Working jsFiddle
为什么不使用转换而不是动画?工作jsFiddle
#blackbox {
background: black;
width: 100px;
height: 80px;
color: white;
text-align: center;
font-family: Times;
font-size: 20px;
position: fixed;
left: 0px;
bottom: 100px;
opacity: 0.5;
margin-bottom: 10px;
transition: all 2s; /* Add this transition */
}
#blackbox:hover { /* Apply the new design on hover */
opacity: 0.8;
width: 800px;
}
#blacktxt {
margin-top: 10px;
height: 60px;
transition: opacity 0.5s, width 5s;
position: absolute;
font-family: cursive;
cursor: default;
}
#blacktxt:hover {
opacity: 0;
}
#2
0
I wrote the jQuery Reversible plugin for this. Its main advantage over CSS transitions is that it works on IE9 and older browsers.
我为此编写了jQuery Reversible插件。它比CSS过渡的主要优点是它适用于IE9和旧版浏览器。