Reputation: 684
How do we pause CSS animation on its state when user hovers the element.
CSS
.container {
height: 160px; width: 450px; background: gray; overflow: hidden;
}
.marquee {
height: 140px; width: 400px; margin: 10px; background: red; position: relative; animation: marquee 10s linear infinite;
}
@keyframes marquee {
0% {left: 100%;}
100% {left: -100%;}
}
.marquee:hover {
/* pause animation. this works but with compatibility issues
animation-play-state is still in W3C working draft
*/
animation-play-state: paused;
}
HTML
<div class="container">
<div class="marquee"></div>
</div>
JAVASCRIPT
$(document).raedy(function() {
$(.marquee).hover { //mouseenter() & mouseleave()
// puase animation
}
});
my jsfiddle link here https://jsfiddle.net/gamss0wa/6/
Upvotes: 4
Views: 786
Reputation: 601
you can pause animation using css
.marquee:hover
{
-webkit-animation-play-state: paused;
-moz-animation-play-state: paused;
-o-animation-play-state: paused;
animation-play-state: paused;
}
Upvotes: 5