How do we add css + animation in jquery?

后端 未结 5 1760
耶瑟儿~
耶瑟儿~ 2021-02-15 12:26

Here is a little snippet of what I\'m trying to do:

$(\'#why-red a\').hover(function() {
    $(this).animate({ -webkit-transform: \'scale(1.1)\'  }, \'slow\');           


        
5条回答
  •  走了就别回头了
    2021-02-15 13:01

    i know this question was asked years ago, but i have found a solution for a similar problem, so i have decided to share. i have used @-webkit-keyframes to create 2 animations. one with .mouseover and one with .mouseout. combining with .addClass and .removeClass I have managed to make this work.

    see example in jsFiddle

    or this snippet code:

    $('#why-red a').mouseover(function() {
    $(this).addClass("scaleAnimation")
    .removeClass("downScaleAnimation")
    .css("-webkit-transform","scale(1.1)");
    })
    $('#why-red a').mouseout(function() {
    $(this).removeClass("scaleAnimation").
    addClass("downScaleAnimation")
    .css("-webkit-transform","scale(1)");
    })
    @-webkit-keyframes scaleAnim {
        0% {-webkit-transform: scale(1);}
        100% {-webkit-transform: scale(1.1);}
    
    }
    @-webkit-keyframes downScaleAnim {
        0% {-webkit-transform: scale(1.1);}
        100% {-webkit-transform: scale(1);}
    
    }
    .scaleAnimation{
        animation: scaleAnim 1s;
        animation-iteration-count: 1;
    }
    .downScaleAnimation{
          animation: downScaleAnim 1s;
        animation-iteration-count: 1;
    }
    #why-red a{position:absolute;}
    
    

提交回复
热议问题