Implementing jQuery's shake effect with animate

前端 未结 9 2486
迷失自我
迷失自我 2020-12-14 10:38

I\'ve been given a cut down subset of the jQuery lib one of the key features I\'m missing is the .effect functions. I do however have .animate. I w

9条回答
  •  执念已碎
    2020-12-14 11:10

    So far I have something like this ..

    jQuery.fn.shake = function(intShakes, intDistance, intDuration) {
        this.each(function() {
            $(this).css("position","relative"); 
            for (var x=1; x<=intShakes; x++) {
            $(this).animate({left:(intDistance*-1)}, (((intDuration/intShakes)/4)))
        .animate({left:intDistance}, ((intDuration/intShakes)/2))
        .animate({left:0}, (((intDuration/intShakes)/4)));
        }
      });
    return this;
    };
    

提交回复
热议问题