jQuery: how do I animate a div rotation?

后端 未结 8 1041
梦毁少年i
梦毁少年i 2020-11-29 05:47

I can rotate a div with css, and jquery .rotate, but i don\'t know how to animate it.

8条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 06:24

    If you're designing for an iOS device or just webkit, you can do it with no JS whatsoever:

    CSS:

    @-webkit-keyframes spin {  
    from {  
        -webkit-transform: rotate(0deg);  
    }  
    to {  
        -webkit-transform: rotate(360deg);  
        } 
    }
    
    .wheel {
        width:40px;
        height:40px;
        background:url(wheel.png);
        -webkit-animation-name: spin; 
        -webkit-animation-iteration-count: infinite; 
        -webkit-animation-timing-function: linear;
        -webkit-animation-duration: 3s; 
    }
    

    This would trigger the animation on load. If you wanted to trigger it on hover, it might look like this:

    .wheel {
        width:40px;
        height:40px;
        background:url(wheel.png);
    }
    
    .wheel:hover {
        -webkit-animation-name: spin; 
        -webkit-animation-iteration-count: infinite; 
        -webkit-animation-timing-function: ease-in-out;
        -webkit-animation-duration: 3s; 
    }
    

提交回复
热议问题