Home >Web Front-end >JS Tutorial >How jQuery achieves jitter effect by extending it_jquery

How jQuery achieves jitter effect by extending it_jquery

WBOY
WBOYOriginal
2016-05-16 16:10:151093browse

The example in this article describes the method of jQuery achieving jitter effect through extension. Share it with everyone for your reference. The specific implementation method is as follows:

1. The JavaScript code is as follows:

Copy code The 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. How to use it:
Copy code The code is as follows:
$(function() {
$('#btn').click(function() {
$(this).shake(2,10,400);
});
});

I hope this article will be helpful to everyone’s jQuery programming.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn