Created
August 6, 2012 04:51
-
-
Save hzlzh/3270711 to your computer and use it in GitHub Desktop.
jQuery shake effect like WordPress Login Form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); //次数,振幅,频率 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.