This article mainly introduces jQuery's method of achieving jitter through expansion, involves jQuery's extension techniques and implementation methods of jitter effects, which has some reference value, for more information about how jQuery achieves jitter through extensions, see the example in this article. Share it with you for your reference. The specific implementation method is as follows:
1. the JavaScript code is as follows:
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. use the following method:
The code is as follows:
$ (Function (){
$ ('# Btn'). click (function (){
$ (This). shake (400 );
});
});
I hope this article will help you with jQuery programming.