Continuous CSS rotation animation on hover, animated back to 0deg on hover out

后端 未结 7 1558
温柔的废话
温柔的废话 2020-11-30 22:26

I have an element that spins when you hover over it indefinitely. When you hover out, the animation stops. Simple:

@-webkit-keyframes rotate {
    from {
            


        
7条回答
  •  醉话见心
    2020-11-30 23:04

    It took a few tries, but I was able to get your jsFiddle to work (for Webkit only).

    There's still an issue with the animation speed when the user re-enters the div.

    Basically, just set the current rotation value to a variable, then do some calculations on that value (to convert to degrees), then set that value back to the element on mouse move and mouse enter.

    Check out the jsFiddle: http://jsfiddle.net/4Vz63/46/

    Check out this article for more information, including how to add cross-browser compatibility: http://css-tricks.com/get-value-of-css-rotation-through-javascript/

提交回复
热议问题