Copy Code code as follows:
<!doctype html>
<meta charset= "Utf-8" >
<title>xxxxxx</title>
<style>
#control {
height:100px;
width:100%;
Background:gray;
}
</style>
<script>
Function Shake (E, oncomplete, distance, interval)
{
if (typeof e = = "string")
{
E = document.getElementById (e);
}//End If
Distance = Distance | | 8;
Interval = Interval | | 800;
var originalstyle = E.style.csstext;
E.style.position = "relative";
var start = (new Date ()). GetTime ();
Animate ();
function animate ()
{
var now = (new Date ()). GetTime ();
var elapsed = Now-start;
var progress = Elapsed/interval;
if (Progress < 1)
{
var y = distance * Math.sin (Math.PI * progress * 4);
var x = distance * Math.Cos (Math.PI * progress * 4);
E.style.left = x + "px";
E.style.top = y + "px";
Console.log (E.style.csstext);
settimeout (animate, Math.min (elapsed));
}//End If
Else
{
E.style.csstext = Originalstyle;
if (OnComplete)
{
OnComplete (e);
}//End If
}//End Else
}//End animate ()
}//End Shake ()
</script>
<body>
<div id= "Control" onclick= "Shake" (this); " >
</div>
</div>
</body>