There is a gear. The animation we are doing now is that the scroll event will be triggered when the mouse is hovering.
The animation I want to make is that after the page is loaded, the gear will roll out and back again after a period of time.
Both right scrolling and left scrolling can be achieved, but I don’t know how to write "after a period of time + roll out and roll back" in jquery
html:
<p id="wheel1">
<p>Running right</p>
</p>
<p id = "wheel2">
<p>Running left</p>
</p>
css:
<style type="text/css">
#wheel1{
width: 150px;
height: 150px;
background-color: pink;
border:5px dotted purple;
border-radius: 80px;
float: right;
}
#wheel2{
width: 150px;
height: 150px;
background-color: pink;
border:5px dotted purple;
border-radius: 80px;
}
#wheel2:hover{
transform: translate(1000px) rotate(720deg);
transition: transform 8s ease;
}
#wheel1:hover{
transform: translate(-500px) rotate(-720deg);
transition: transform 8s ease;
}
p{
font-size: 25px;
color: white;
margin: 30px;
}
Use the
setInterval
function every once in a while:Method 1: Pure CSS implementation
Add left scrolling and right scrolling styles to the two gears
html
Added infinite loop scrolling animation to the style.
If you need to go out and come back after a while, you can increase the value of
translate(-1000px)
, such as 2000px, and control it according to your needs.After the value of translate increases, the value of rotate needs to be increased accordingly, and you can just adjust it according to your needs.
css
Method 2: Use jquery control
If you want to use jquery control, the css needs to be modified
js