Reset transform: rotate() without invoking -webkit-transition: style

后端 未结 1 614
Happy的楠姐
Happy的楠姐 2021-01-23 16:07

I am drawing a wheel on a canvas, rotating it and then wanting to reset the rotation to 0. however due to the css property: -webkit-transition: -webkit-transform 15s ease;

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-23 16:40

    I think I have a solution for this. By changing the css class to a 'default rotation' class briefly before changing the class to your animated rotation class you can control the animation timing on each separate class in order to have the wheel snap back to the starting position before rotating to your new position.

    css:

    .spin0 {
        transform: rotate(0deg);    
    }
    
    .spin750 {
        transform: rotate(750deg) !important;
        transition-duration: 2.5s !important;
    }
    

    js (on click):

    element.className = "spin0";
    
    setTimeout(function(){
        element.className = "spin750";
    }, 10); 
    

    0 讨论(0)
提交回复
热议问题