jQuery extends the method of jitter effect

  • 2020-05-12 02:13:36
  • OfStack

This article illustrates how jQuery extends the jitter effect. Share with you for your reference. The specific implementation method is as follows:

1. The JavaScript code is as follows:

jQuery.fn.shake = function(intShakes /*Amount of shakes*/, intDistance /*Shake distance*/, intDuration /*Time duration*/) {
    this.each(function() {
        var jqNode = $(this);
        jqNode.css({position: ' relative'});
        for (var x=1; x<=intShakes; x++) {
            jqNode.animate({ left: (intDistance * -1) },(((intDuration / intShakes) / 4)))
            .animate({ left: intDistance },((intDuration/intShakes)/2))
            .animate({ left: 0 },(((intDuration/intShakes)/4)));
        }
    });
    return this;
}

2. Usage:
$(function() {
  $('#btn').click(function() {
    $(this).shake(2,10,400);
  });
});

I hope this article is helpful for you to design jQuery program.


Related articles: