<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <meta http-equiv=" Content-type "content= "Text/html; Charset=utf-8 "/> <style type=" Text/css "> #body {text-align:center;} #test {width:119px;position:absolute;margin:10px auto;height:114px;background:url (/images/logo.gif); border:2px Dotted red;} </style> <script type= "Text/javascript" ></script> </pead> <body> <di V > <div><input type= "button" value= "~ ~ ~ Let me Shake It ~ ~" onclick= "Nn.start ()"/></div> < Div><input type= "button" value= "Don't tremble." onclick= "Nn.stop ()"/></div> <div id= "test" ></d iv> </div> </body> </ptml> <script type= "Text/javascript" > var M=document.getel Ementbyid ("test"); function Skclass (obJ,rate,speed) {var ol=obj.offsetleft; var ot=obj.offsettop; This.stop=null; This.otime=null; this.state=0; var om=this; This.start=function () {if (this.state==0) {Ostart (); this.state=1; Else{alert ("So you can't bear it?") ')} ' var ostart=function () {if (parseint (obj.style.left) ==ol-2) {Obj.style.top =ot+2+ "px"; settimeout (function () {obj.style.left=ol+2+ "px"},rate)} else{obj.style.top=o t-2+ "px"; settimeout (function () {obj.style.left=ol-2+ "px"},rate)} om.otime=settimeout (function () {Ostart ()},spe ED); } this.stop=function () {cleartimeout (om.otime); this.state=0; } var nn=new skclass (m,20,50); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]