Rotating an image continuously in web development is typically done for visual effects and user engagement. Here are some specific purposes and applications for continuously rotating images:
To rotate an image continuously in CSS, you can use CSS animations. Here is an example of how to achieve this:
<style>
.rotate {
width: 100px;
height: 100px;
animation: spin 5s linear infinite;
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
</style>
<img src="/img/avatar.mraces.run@300w.png" alt="Rotating Image" class="rotate">
In this example:
.rotate
class applies the animation to the image.animation
property specifies the animation name (spin
), duration (5s
), timing function (linear
), and that it should run infinitely.@keyframes
rule defines the spin
animation, rotating the image from 0 degrees to 360 degrees.You can adjust the duration to make the rotation faster or slower by changing the 5s
value to your preferred duration.