标签:doc nbsp clear code html body doctype abs The
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> #div1{ width: 100px; height: 100px; background: red; position: absolute; top: 500px; } </style> <script> window.onload=function(){ var oDiv=document.getElementById("div1"); var oInput=document.getElementById("input1"); var timer=null; var iSpeed=-40; var iSpeedX=10; oInput.onclick=function(){ startMove(); } function startMove(){ clearInterval(timer); timer=setInterval(function(){ iSpeed+=3; var T=oDiv.offsetTop+iSpeed; if(T>document.documentElement.clientHeight-oDiv.offsetHeight){ T=document.documentElement.clientHeight-oDiv.offsetHeight; iSpeed*=-1; iSpeed*=0.75; iSpeedX*=0.75; } oDiv.style.top=T+"px"; oDiv.style.left=oDiv.offsetLeft+iSpeedX+"px"; },30) } } </script> </head> <body> <input type="button" value="开始运动" id="input1" /> <div id="div1"></div> </body> </html>
标签:doc nbsp clear code html body doctype abs The
原文地址:https://www.cnblogs.com/gxywb/p/10244567.html