I have the following piece of code:
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;
};
The problem is that when I apply it, if the object is positioned absolutely in the center, it makes the object jump to the left of the page.
Can this be fixed? and how if it can?
I think using “margin-left” instead of “left” in your animate styles will have a better effect. You may need to play around with relative positioning etc. if it does not work first time