简体   繁体   中英

CSS Rotate Icon Animation

How do I archive the following using CSS?

1.Rotates image A multiple times then switch to image B when the mouse positions on the image.

2.Rotates back to image A when mouse clicks or leave the image.

Thanks

You can do what you want by using CSS transform and transition properties. It's really easy, but you'll need to use a div with background-image instead of an img tag:

div{
    width:50px;
    height:50px;
    background:url("normalImage.png");
    transition:2.5s; /* Transition duration */
}
div:hover{
    background:url("imageThatAppearsAfterHovering.png");
    -o-transform:rotate(720deg);
    -ms-transform:rotate(720deg);
    -moz-transform:rotate(720deg);
    -webkit-transform:rotate(720deg);
    transform:rotate(720deg); /* How many times it'll rotate = degrees÷360 */
}

JSFiddle Demo

JSFiddle Demo using ultra high speeds

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM