xxxxxxxxxx
<!DOCTYPE html>
<html>
<head>
<style>
/* Define the animation */
@keyframes move {
0% { transform: translateX(0); } /* Initial position */
50% { transform: translateX(200px); } /* Intermediate position */
100% { transform: translateX(0); } /* Final position */
}
/* Apply the animation to an element */
.box {
width: 100px;
height: 100px;
background-color: blue;
animation: move 2s infinite; /* Run the animation for 2 seconds and repeat indefinitely */
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
xxxxxxxxxx
with the help of animation properties in CSS we can control
how the animation will be played throughout.
The animation properties in CSS are -
1) animation-duration : implies the time taken by the animation to finish.Forexample- animation-duration: 6s;
2) animation-direction : implies the direction of the animation.Forexample- the direction in which the horse rides , the car moves , the insects crawls.
3) animation-delay: implies the time after which is the animation starts.Forexample- animation-delay: 3s; means after 3seconds the animation will start.
4) animation-iteration-count: implies how many times the animation will repeat.
5) animation-timing-function: the values can be ease,ease-in, ease-out, linear, ease-in-out.
6) animation-play-state: the values can be paused, running, initial, inherit.
7) animation-name: implies the name of the animation which is assigned by us.
8) animation-fill-mode: it specifies a style for the element when the animation is not playing.The values can be none,forwards, backwards, both, initial and inherit.
9) @keyframes: this is the most important.It specifies the different values of style in different intervals of time.The animation-name is used in @keyframes declaration.
NOTE: the syntax of every single letter, numbers, punctuation mark is very important.
xxxxxxxxxx
<!DOCTYPE html>
<html>
<style>
#container {
width: 400px;
height: 400px;
border-radius: 10%;
position: relative;
background: rgb(130, 240, 231);
}
#animate {
width: 50px;
height: 50px;
border-radius: 50%;
border: 3px solid rgb(218, 15, 15);
position: absolute;
background-color: rgb(51, 255, 0);
}
</style>
<body>
<p><button onclick="myMove()">Click Me</button></p>
<div id ="container">
<div id ="animate"><br><p>(★‿★)</p></div>
<br><br>
<br><p>hello from mohammad alshraideh</p>
</div>
<script>
function myMove() {
let id = null;
const elem = document.getElementById("animate");
let pos = 0;
clearInterval(id);
id = setInterval(frame, 5);
function frame() {
if (pos == 350) {
clearInterval(id);
} else {
pos++;
elem.style.top = pos + "px";
elem.style.left = pos + "px";
}
}
}
</script>
</body>
</html>
xxxxxxxxxx
Name Last modified Size Description mail-notifiction.html 2021-05-12 01:38 4.4K Hypertext Markup Language
Day-night.html 2021-05-12 02:56 8.4K Hypertext Markup Language