有简单例子,如何处理这种情况?
时间:2010-05-13
来源:互联网
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Demo</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <style> *{margin:0;padding:0;font-size:12px;text-decoration:none} </style> <script> function go(num){ var box=document.getElementById("box"); var show=document.getElementById("show"); var t,i=0; t=setInterval(function(){ if(i>=num){ //box.style.left=num+"px"; clearInterval(t); }; i+=3; box.style.left=i+"px"; show.innerHTML=parseInt(box.style.left); },20) } window.onload=function(){ go(200); } </script> </head> <body> <div id="box" style="width:50px;height:50px;background:red;position:absolute;left:0;top:0"></div> <div id="show"></div> </body> </html>
提示:您可以先修改部分代码再运行
有没有什么聪明点的办法??还请劳驾帮忙点化点化.提示:您可以先修改部分代码再运行
我要它不管步长i是多少,到200就给我停下,别多走!!
作者: hotcrab2008 发布时间: 2010-05-13
点化谈不上,就这样将就着用吧。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Demo</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <style> *{margin:0;padding:0;font-size:12px;text-decoration:none} </style> <script> function go(num){ var box=document.getElementById("box"); var show=document.getElementById("show"); var t,i=0; t=setInterval(function(){ if(i>=num){ clearInterval(t); box.style.left = num + "px"; return; }; i+=3; box.style.left=i+"px"; i<=num ? show.innerHTML=parseInt(box.style.left) : show.innerHTML=num; },20) } window.onload=function(){ go(200); } </script> </head> <body> <div id="box" style="width:50px;height:50px;background:red;position:absolute;left:0;top:0"></div> <div id="show"></div> </body> </html>
提示:您可以先修改部分代码再运行
提示:您可以先修改部分代码再运行
作者: chenjmdgjl 发布时间: 2010-05-13
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28