HTML Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" /><!-- Declare character encoding -->
<title>How to play the animation two times</title><!-- Set the title of the HTML document -->
</head>
<body>
<div class="animation">
<div class="w3r">
w3resource Tutorial
</div>
</div>
<style type="text/css"> /* CSS style start*/
.w3r {
color: white; /* Set text color */
float: left; /* Float the text to the left */
margin-right: 2%; /* Set right margin */
font-size: 20px; /* Set font size */
}
.animation {
background-color: #CC3333; /* Set background color */
height: 50px; /* Set height */
width: 100%; /* Set width */
overflow: hidden; /* Hide overflow content */
}
div {
width: 100px; /* Set width */
height: 100px; /* Set height */
background: #33FFFF; /* Set background color */
position: relative; /* Set position to relative */
-webkit-animation: move 5s infinite; /* Chrome, Safari, Opera */ /* Apply animation to Webkit browsers */
-webkit-animation-iteration-count: 5s; /* Chrome, Safari, Opera */ /* Set iteration count for Webkit browsers */
animation: move 5s infinite; /* Apply animation */
animation-iteration-count: 2; /* Set iteration count for animation */
}
/* Chrome, Safari, Opera */
@-webkit-keyframes move {
from {top: 0px;} /* Define initial position */
to {top: 200px;} /* Define final position */
}
@keyframes move {
from {top: 0px;} /* Define initial position */
to {top: 200px;} /* Define final position */
}
</style>
</body>
</html>
Explanation:
Live Demo:
See the Pen animation-iteration-count-answer by w3resource (@w3resource) on CodePen.
See the solution in the browser
Supported browser
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4