<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> <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="保存代码"> <a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">[Ctrl A すべて選択 注: </a>外部 Js を導入する必要がある場合は、</div> を実行するために更新する必要があります]<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>