Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@hzxie 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
You can’t perform that action at this time.