Skip to content

Instantly share code, notes, and snippets.

@hzlzh
Created August 6, 2012 04:51
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save hzlzh/3270711 to your computer and use it in GitHub Desktop.
Save hzlzh/3270711 to your computer and use it in GitHub Desktop.
jQuery shake effect like WordPress Login Form
jQuery.fn.shake = function(intShakes, intDistance, intDuration) {
this.each(function() {
$(this).css({
position: "relative"
});
for (var x = 1; x <= intShakes; x++) {
$(this).animate({
left: (intDistance * -1)
}, (((intDuration / intShakes) / 4))).animate({
left: intDistance
}, ((intDuration / intShakes) / 2)).animate({
left: 0
}, (((intDuration / intShakes) / 4)));
}
});
return this;
};
// demo use
$('form').shake(2, 13, 250); //次数,振幅,频率
@hzxie
Copy link

hzxie commented Nov 20, 2013

It didn't work.

I use following code to test your code:
$('#submit').click(function(){
$('form').shake(2, 13, 250);
alert('stop!');
});

The alert window appeared but the form doesn't shake. Can't you tell me the reason?

BTW: I'm using JQuery 1.10.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment