html元素摇摆

<script type="text/javascript" src="jquery-1.9.0.min.js"></script>
<script type="text/javascript">
jQuery.fn.shake = function(intShakes /*Amount of shakes*/, intDistance /*Shake distance*/, intDuration /*Time duration*/) {
    this.each(function() {
        var jqNode = $(this);
        jqNode.css({position: 'relative'});
        for (var x=1; x<=intShakes; x++) {
            jqNode.animate({ left: (intDistance * -1) },(((intDuration / intShakes) / 4))).animate({ left: intDistance },((intDuration/intShakes)/2)).animate({ left: 0 },(((intDuration/intShakes)/4)));
        }
    });
    return this;
}
$(function() {
  $('#div1').click(function() {
    $(this).shake(5,10,400);
  });
});


</script>
<body>
<div id="div1" style="width:20px;height:20px;background:red;"></div>
</body>

你可能感兴趣的:(html)