how to wait for css transition to finish before applying next class

前端 未结 3 414
死守一世寂寞
死守一世寂寞 2021-01-03 19:27

I\'m trying to get text to \"swing\", by applying a rotation transition one way, followed by a rotation the next way, when hovered over. However, it doesn\'t wait for the fi

相关标签:
3条回答
  • 2021-01-03 19:42

    How about just apply one class with the jQuery, then let CSS do the rest. You can use percentage of time in keyframes to determine what happens throughout the animation. Like so:

    @keyframes name {
      0% { transform: rotate(0deg); }
      50% { transform: rotate(-20deg); }
      100% { transform: rotate(360deg); } }
    @-o-keyframes name {
      0% { -o-transform: rotate(0deg); }
      50% { -o-transform: rotate(-20deg); }
      100% { -o-transform: rotate(360deg); } } 
    @-moz-keyframes name {
      0% { -moz-transform: rotate(0deg); }
      50% { -moz-transform: rotate(-20deg); }
      100% { -moz-transform: rotate(360deg); } }
    @-webkit-keyframes name {
      0% { -webkit-transform: rotate(0deg); }
      50% { -webkit-transform: rotate(-20deg); }
      100% { -webkit-transform: rotate(360deg); } }
    
    0 讨论(0)
  • 2021-01-03 19:53

    Each browser has its own event that you can use to detect transition end, just bind like this :

    $(".yourClass").on('transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd', 
        function() {
             //doSomething
        });
    
    0 讨论(0)
  • 2021-01-03 20:07

    For css3 transitions with jquery I suggest using jquery.transit. It provides a jquery.animate like api and callbacks that would work in your case.

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