Ich versuche mit reinem Javascript, um eine CSS3-Animation zu erstellen, funktioniert es. Und dann möchte ich, dass diese Animation anhalten kann, wenn die Maus in den Container eindringt und läuft, wenn die Maus den Container verlässt. Ich benutze animate.pause
, animate.play
& animationPlayState
, aber es funktioniert immer noch nicht. Also, wie funktioniert es? Entschuldige mein Englisch, vielen Dank!mit Javascript zu steuern CSS3 Animation Pause und
Hier ist mein Code:
window.onload = function() {
\t var ulNode = document.querySelector(".container>ul"),
\t \t frames = [
\t \t \t {left: 0},
\t \t \t {left: '-700px'},
\t \t \t {left: 0}
\t \t ],
\t \t timing = {
\t \t \t duration: 10000,
\t \t \t iterations: Infinity,
\t \t };
\t ulNode.animate(frames, timing);
\t var player = ulNode.animate(frames);
\t ulNode.onmouseover = function(){
\t \t // player.pause();
\t \t this.style.animationPlayState = "paused";
\t }
\t ulNode.onmouseout = function(){
\t \t // player.play();
\t \t this.style.animationPlayState = "running";
\t }
}
body,ul{margin: 0; padding: 0;}
.container{
width: 500px;
height: 100px;
position: relative;
margin: 0 auto;
overflow: hidden;
}
ul{list-style-type: none; position: absolute; left: 0; top: 0; width: 1200px;}
ul>li{width: 100px; height: 100px; float: left;}
ul>li:nth-child(odd){background-color: red;}
ul>li:nth-child(even){background-color: green;}
/*@keyframes doMove{
\t form{left: 0;}
\t 50%{left: -700px;}
\t to{left: 0px;}
}
ul{animation: doMove 20s linear infinite;}
.container:hover ul{animation-play-state:paused;}*/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CSS3 Animation</title>
</head>
<body>
<div class="container">
\t <ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</body>
</html>
so nett von Ihnen. Ja, ich denke auch, dass 'WebkitAnimationPlayState' die richtige Syntax ist, aber es funktioniert nicht. Hat vielleicht einen anderen Grund oder wird nicht unterstützt. –
Ja, es ist bedauerlich, ich habe es mit und ohne Initialisierung in CSS versucht, aber ohne Erfolg :( –
'Webkit' oder' webkit' mit Kleinbuchstaben ersten Buchstaben? – Qwertiy