2016-06-20 6 views
4

CSSアニメーションを、ユーザーが要素を移動させたときの状態で一時停止するにはどうすればいいですか?jqueryを使用してホバー上でCSSアニメーションを一時停止する方法

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 
    } 
}); 

ここで私のjsfiddleリンクhttps://jsfiddle.net/gamss0wa/6/

答えて

5

あなたはCSSに

.marquee:hover 
{ 
    -webkit-animation-play-state: paused; 
    -moz-animation-play-state: paused; 
    -o-animation-play-state: paused; 
    animation-play-state: paused; 
} 
+0

素敵な感謝を使ってアニメーションを一時停止することができます。私は、cssのアニメーション再生状態が存在するかどうかはわかりませんでした。 –

+0

私はちょうどあなたの解決策を使用して互換性の問題を怖がっています。 –

+0

同じことCSSのアニメーションはブラウザで動作し、そうでなければアニメーション再生状態は動作しません –

関連する問題