How to do a transform scale animation with jQuery?

前端 未结 1 342
广开言路
广开言路 2021-01-13 07:07

I\'m trying achieve and \"opening-window\" animation, I tried the following:

import $ from \'jquery\'

export const fade = {
  css: false,
  enter: function          


        
1条回答
  •  时光说笑
    2021-01-13 07:43

    Of course that css transition is much better then jQuery animate.

    Here is a generic example of how animate transform with jQuery.

    The trick is to set unaffected css property (like border-spacing) and "animate" it. Then, you can use the step callback to create your own animation effect.

    $('button').click(function() {
      $('div').css('borderSpacing', 1).animate(
        {
          borderSpacing: 1.3
        },
        {
        step: function(now,fx) {
          $(this).css('transform','scale('+now+')');  
        },
        duration:'slow'
      });
    });
    div {
      width:150px;
      height:150px;
      background:green;
    }
    
    

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