<div class="htmlarea"> <textarea id="runcode25049"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>JavaScript物体平移运动特效</title> <style> #div1 {background: red url(http://www.jb51.net/images/logo.gif); position:absolute; left:50px; top:50px; width:200px; height:200px;} </style> <script type="text/javascript"> var g_oTimer=null; function startMove() { if(!g_oTimer) { g_oTimer=setInterval(moveTimerHandler, 30); } } function moveTimerHandler() { var oDiv=document.getElementById('div1'); var iSpeed=5; if(oDiv.offsetLeft>=300) { clearInterval(g_oTimer); g_oTimer=null; } else { oDiv.style.left=oDiv.offsetLeft + iSpeed + 'px'; } } window.onload=function () { var oBtn=document.getElementById('btn_start_move'); oBtn.onclick=startMove; }; </script> <div id="div1"></div> <input id="btn_start_move" type="button" value="开始运动"> </textarea><br><input onclick="runEx('runcode25049')" type="button" value="运行代码"> <input onclick="doCopy('runcode25049')" type="button" value="复制代码"> <input onclick="doSave(runcode25049)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>