看看,你们应该能看我的意图,但是我写不出来后半句!!

dugucan 2002-07-21 11:37:59
<script>
x=0
y=0
function fly()
{
if(x<400)
{x++;y++
clearTimeout(timeoutid)
self.moveTo(x,y)
timeoutid=setTimeout("fly()",20)
} /*从这里开始,后面是水货,教我*/
else(x>=400){
x=400
y=400
clearTimeout(timeoutid)
self.moveTo(x--,y--)
timeoutid=setTimeout("fly()",10)
}
}
</script>
<body onload=fly()>
<body>
...全文
28 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xdspower 2002-08-13
  • 打赏
  • 举报
回复
要控制循环次数的正确代码(上次有错):
<script>
x=0
y=0
var step=1;
var timeoutid;
var count=0;
function fly()
{
if(count<10)//最多循环10次
{
x+=step;y+=step;
clearTimeout(timeoutid);
self.moveTo(x,y);
timeoutid=setTimeout("fly()",10);
if (x>400) step=-1;
if (x<1) {step=1;count++;}//上次这里把step 写为了tep
}
}
</script>

llrock 2002-07-22
  • 打赏
  • 举报
回复
<script>
x=0
y=0
timeoutid=null;
function fly(){
if(x<400){
x++;
y++
clearTimeout(timeoutid)
self.moveTo(x,y)
timeoutid=setTimeout("fly()",20)
}else if(x>=400){ /*从这里开始,后面是水货,教我*/
x=400
y=400
clearTimeout(timeoutid)
self.moveTo(x--,y--)
timeoutid=setTimeout("fly()",10)
}
}
</script>
<body onload=fly()>
<body>
emu 2002-07-22
  • 打赏
  • 举报
回复
哈哈,鸡蛋里面也有骨头的
xdspower 2002-07-22
  • 打赏
  • 举报
回复
<script>
x=0
y=0
var step=1;
var timeoutid;
function fly()
{
x+=step;y+=step;
clearTimeout(timeoutid);
self.moveTo(x,y);
timeoutid=setTimeout("fly()",10);
if (x>400) step=-1;
if (x<1) step=1;
}
</script>
代码是对的,要控制循环次数就还要引入一个全局控制变量,比如
<script>
x=0
y=0
var step=1;
var timeoutid;
var count=0;
function fly()
{
if(count<10)//最多循环10次
{
x+=step;y+=step;
clearTimeout(timeoutid);
self.moveTo(x,y);
timeoutid=setTimeout("fly()",10);
if (x>400) step=-1;
if (x<1) {tep=1;count++;}
}
}
</script>

emu 2002-07-22
  • 打赏
  • 举报
回复
要反复来回还是只要一个来回?
反复来回象这样:
<html>
<head>
<script>
x=0
y=0
var step=1;
var timeoutid;
function fly()
{
x+=step;y+=step
clearTimeout(timeoutid)
self.moveTo(x,y)
timeoutid=setTimeout("fly()",10)
if (x>400) step=-1
if (x<1) step=1
}
</script>
</head>
<body onload=fly()>
</body>
</html>

一个来回的话,把setTimeout改成 if(x>0) setTimeout就成了

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧