一段产生某种特效的代码,我觉得没错误了,但运行不了

i33333 2004-09-21 09:18:07

<script language="JavaScript"><!--
Image0=new Image();
Image0.src="a.gif";
Amount=15;

Ypos=new Array();
Xpos=new Array();
Speed=new Array();
rate=new Array();
grow=new Array();
Step=new Array();
Cstep=new Array();
nsSize=new Array();
ns=(document.layers)?1:0;
WinHeight=(document.layers)?window.innerHeight:window.document.body.clientHeight;
WinWidth=(document.layers)?window.innerWidth:window.document.body.clientWidth;
for (var i=0; i < Amount; i++){
Ypos[i] = Math.round(Math.random()*WinHeight);
Xpos[i] = Math.round(Math.random()*WinWidth);
Speed[i]= Math.random()*4+4;
Cstep[i]=0;
Step[i]=Math.random()*0.1+0.05;
grow[i]=10;
nsSize[i]=Math.random()*15+5;
}
if (ns){
for (i = 0; i < Amount; i++){
document.write("<LAYER NAME='sn"+i+"' LEFT=0 TOP=0><img src='+Image0.src+' name='N' width='+nsSize[i]+' height='+nsSize[i]+'></LAYER>");
}
}
else{
document.write("<div style='position:absolute;top:0px;left:0px'><div style='position:relative'>");
for (i = 0; i < Amount; i++){
document.write("<img id='si' src='"+Image0.src+"' style='position:absolute;top:0px;left:0px;filter:alpha(opacity=60)'>");
}
document.write("</div></div>");
}
function bubbles(){
var WinHeight=(document.layers)?window.innerHeight:window.document.body.clientHeight;
var WinWidth=(document.layers)?window.innerWidth:window.document.body.clientWidth;
var hscrll=(document.layers)?window.pageYOffset:document.body.scrollTop;
var wscrll=(document.layers)?window.pageXOffset:document.body.scrollLeft;
for (i=0; i < Amount; i++){
sy = Speed[i]*Math.sin(270*Math.PI/180);
sx = Speed[i]*Math.cos(Cstep[i]);
Ypos[i]+=sy;
Xpos[i]+=sx;
rate[i]=0.4;
if (Ypos[i] < -50){
Ypos[i]=WinHeight+50;
Xpos[i]=Math.round(Math.random()*WinWidth);
Speed[i]=Math.random()*4+6;
grow[i]=2;
nsSize[i]=Math.random()*15+5;
}
if (ns){
document.layers["sn"+i].left=Xpos[i]+wscrll;
document.layers["sn"+i].top=Ypos[i]+hscrll;
}
else{
si[i].style.pixelLeft=Xpos[i]+wscrll;
si[i].style.pixelTop=Ypos[i]+hscrll;
si[i].style.width=grow[i];
si[i].style.height=grow[i];
}
grow[i]+=rate[i];
Cstep[i]+=Step[i];
if (grow[i] > 24) grow[i]=25;
}
setTimeout("bubbles()",50);
}
bubbles();
-->
</script>

===================================================================================
应该产生几幅小图片向上飘的效果,但不行。MS FrontPage 2000提示是 行 23 字符 3 错误,缺少对象。
请高手指点
...全文
113 9 打赏 收藏 举报
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
i33333 2004-10-09
  • 打赏
  • 举报
回复
UP
i33333 2004-10-01
  • 打赏
  • 举报
回复
Ypos[i]+=sy; Ypos[i]-=sy;
Xpos[i]+=sx; ----------> Xpos[i]-=sx;

让它往下飘,怎么只飘一次就不飘了??

应该怎么改?

onkey1999 2004-09-21
  • 打赏
  • 举报
回复
都可以运行,没什么问题
DARKNESSFALL 2004-09-21
  • 打赏
  • 举报
回复
确实很漂亮!
hanyun229 2004-09-21
  • 打赏
  • 举报
回复
其实放在<body>……</body>之间是必须的,至少对于你这个效果,还有就是双引号没有写好
hanyun229 2004-09-21
  • 打赏
  • 举报
回复
<html>
<body>
<script language="JavaScript"><!--
Image0=new Image();
Image0.src="a.gif";
Amount=15;

Ypos=new Array();
Xpos=new Array();
Speed=new Array();
rate=new Array();
grow=new Array();
Step=new Array();
Cstep=new Array();
nsSize=new Array();
ns=(document.layers)?1:0;
WinHeight=(document.layers)?window.innerHeight:window.document.body.clientHeight;
WinWidth=(document.layers)?window.innerWidth:window.document.body.clientWidth;
for (var i=0; i < Amount; i++){
Ypos[i] = Math.round(Math.random()*WinHeight);
Xpos[i] = Math.round(Math.random()*WinWidth);
Speed[i]= Math.random()*4+4;
Cstep[i]=0;
Step[i]=Math.random()*0.1+0.05;
grow[i]=10;
nsSize[i]=Math.random()*15+5;
}
if (ns){
for (i = 0; i < Amount; i++){
document.write("<LAYER NAME='sn"+i+"' LEFT=0 TOP=0><img src='"+Image0.src+"' name='N' width='"+nsSize[i]+"' height='"+nsSize[i]+"'></LAYER>");
}
}
else{
document.write("<div style='position:absolute;top:0px;left:0px'><div style='position:relative'>");
for (i = 0; i < Amount; i++){
document.write("<img id='si' src='"+Image0.src+"' style='position:absolute;top:0px;left:0px;filter:alpha(opacity=60)'>");
}
document.write("</div></div>");
}
function bubbles(){
var WinHeight=(document.layers)?window.innerHeight:window.document.body.clientHeight;
var WinWidth=(document.layers)?window.innerWidth:window.document.body.clientWidth;
var hscrll=(document.layers)?window.pageYOffset:document.body.scrollTop;
var wscrll=(document.layers)?window.pageXOffset:document.body.scrollLeft;
for (i=0; i < Amount; i++){
sy = Speed[i]*Math.sin(270*Math.PI/180);
sx = Speed[i]*Math.cos(Cstep[i]);
Ypos[i]+=sy;
Xpos[i]+=sx;
rate[i]=0.4;
if (Ypos[i] < -50){
Ypos[i]=WinHeight+50;
Xpos[i]=Math.round(Math.random()*WinWidth);
Speed[i]=Math.random()*4+6;
grow[i]=2;
nsSize[i]=Math.random()*15+5;
}
if (ns){
document.layers["sn"+i].left=Xpos[i]+wscrll;
document.layers["sn"+i].top=Ypos[i]+hscrll;
}
else{
si[i].style.pixelLeft=Xpos[i]+wscrll;
si[i].style.pixelTop=Ypos[i]+hscrll;
si[i].style.width=grow[i];
si[i].style.height=grow[i];
}
grow[i]+=rate[i];
Cstep[i]+=Step[i];
if (grow[i] > 24) grow[i]=25;
}
setTimeout("bubbles()",50);
}
bubbles();
-->
</script>
</body>
</html>

是有点问题,改了一点,再去看看,应该可以了
zltostem 2004-09-21
  • 打赏
  • 举报
回复
没错误,挺漂亮~~~
wwj9252003 2004-09-21
  • 打赏
  • 举报
回复
我的也没有问题,ie5

把它放在<body></body>中间
wangxiaomax 2004-09-21
  • 打赏
  • 举报
回复
我测试了,没问题。我的是IE6SP1
相关推荐
发帖
JavaScript

8.7w+

社区成员

Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
帖子事件
创建了帖子
2004-09-21 09:18
社区公告
暂无公告