JSFiddle - React, Tailwind, and code Playground
by gion_13
HTML
<div id="a"></div>
CSS
#a{
width : 40px;
height : 40px;
background-color : red;
top : 50%;
left : 50%;
position : absolute;
}
JavaScript
jQuery.fn.shake = function(intShakes, intDistance, intDuration) {
function shakeOneTime(){
var $this = this;
$this
.animate({marginLeft:(intDistance*-1)}, (((intDuration/intShakes)/4)),function(){
$this.animate({marginLeft:intDistance}, ((intDuration/intShakes)/2),function(){
$this.animate({marginLeft:0}, (((intDuration/intShakes)/4)),function(){
if(--intShakes >= 0)
shakeOneTime.call($this);
});
});
});
}
return this.each(function() {
shakeOneTime.call($(this));
});
};
$(function(){
$('#a').shake(3,100,2000);
});