xxxxxx
<script><BR> function shake(e, onComplete, distance, interval)<BR> {<BR> if (typeof e === "string")<BR> {<BR> e = document.getElementById(e);<BR> } // end if<BR> distance = distance || 8;<BR> interval = interval || 800;
<P> var originalStyle = e.style.cssText;<BR> e.style.position = "relative";<BR> var start = (new Date()).getTime();
<P> animate();
<P> function animate()<BR> {<BR> var now = (new Date()).getTime();<BR> var elapsed = now - start;<BR> var progress = elapsed / interval;<BR> if (progress < 1)<BR> {<BR> var y = distance * Math.sin(Math.PI * progress * 4);<BR> var x = distance * Math.cos(Math.PI * progress * 4);<BR> e.style.left = x + "px";<BR> e.style.top = y + "px";<BR> console.log(e.style.cssText);<BR> setTimeout(animate, Math.min(25, elapsed));<BR> } // end if<BR> else<BR> {<BR> e.style.cssText = originalStyle;<BR> if (onComplete)<BR> {<BR> onComplete(e);<BR> } // end if
<P> } // end else
<P> } // end animate()
<P> } // end shake()
<P> </script>