JQuery uses extensions to achieve jitter.
This article describes how jQuery achieves jitter through extension. Share it with you for your reference. The specific implementation method is as follows:
1. The JavaScript code is as follows:
Copy codeThe 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. Use the following method:
Copy codeThe Code is as follows: $ (function (){
$ ('# Btn'). click (function (){
$ (This). shake (400 );
});
});
I hope this article will help you with jQuery programming.