Skip to content

Instantly share code, notes, and snippets.

@fritids
Forked from hzlzh/jQuery.fn.shake.js
Created March 23, 2013 00:28
Show Gist options
  • Save fritids/5225762 to your computer and use it in GitHub Desktop.
Save fritids/5225762 to your computer and use it in GitHub Desktop.
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