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:
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:
$(function() {
$('#btn').click(function() {
$(this).shake(2,10,400);
});
});
I hope this article will be helpful to everyone’s jQuery programming.