楼主的代码看起来不爽...运行时提示initializeBall1();出错:找不到对象
但两个图还是移动的.
但两个图还是移动的.
解决方案 »
- 调用js函数返回值
- 请问怎么实现在textarea光标处插入表情?
- 请教一个JavaScript的小问题!
- 关于防止表单多次提交的问题(在线等待) 有代码 希望高手帮助改下,急急急~~~~
- 在网页怎样点击按钮弹出一个层并可以移动
- mailto正文中的换行符
- sea.js模块化结果为null
- 用javascript可不可以刷新别的窗口,要怎样做?
- 关天IE窗口的问题……
- 求助Js解密,本人第一次遇见这种加密【$$=~[];$$={___:开头的】。
- "Oops! That does not apperar to be a valid number. Please try again"这是由于什么原因引起的错误?
- 判断分辨率
function prog(){
initializeBall();
initializeBall1();
temp();
}下面是在EDITPLUS 2.11英文版, IE 6.0.2800.1106中文版通过的代码:<HTML>
<HEAD>
<script language="JavaScript">
<!--
//设置下面一些参数,小球移动速度1-50,数值大速度快;
var ballWidth = 40;
var ballHeight = 40;
var BallSpeed = 2;var maxBallSpeed = 50;
var xMax;
var yMax;
var xPos = 0;
var yPos = 0;var xDir = "right"; //水平方向向右移动
var yDir = "down"; //垂直方向向下移动
var superballRunning = true;
var tempBallSpeed;
var currentBallSrc;
var newXDir;
var newYDir;function InitBall()
{
if (document.all)
{
xMax = document.body.clientWidth;
yMax = document.body.clientHeight;
document.all("superball").style.visibility = "visible";
}
else
{
if (document.layers)
{
xMax = window.innerWidth;
yMax = window.innerHeight;
document.layers["superball"].visibility = "show";
}
} setTimeout('moveBall()',400);
}
function InitBall2()
{
if (document.all)
{
xMax2 = document.body.clientWidth;
yMax2 = document.body.clientHeight;
document.all("superball2").style.visibility = "visible";
}
else
{
if (document.layers)
{
xMax2 = window.innerWidth;
yMax2 = window.innerHeight;
document.layers["superball2"].visibility = "show";
}
} setTimeout('moveBall2()', 400);
}
function moveBall()
{
if (superballRunning==true)
{
calculatePosition();
if (document.all)
{
document.all("superball").style.left = xPos + document.body.scrollLeft;
document.all("superball").style.top = yPos + document.body.scrollTop;
}
else
{
if (document.layers)
{
document.layers["superball"].left = xPos + pageXOffset;
document.layers["superball"].top = yPos + pageYOffset;
}
} setTimeout('moveBall()',30);
}
}/*
function calculatePosition()
{
if (xDir == "right")
{
if (xPos > (xMax - ballWidth - BallSpeed))
{
xDir = "left";
}
}
else
{
if (xDir == "left")
{
if (xPos < (0 + BallSpeed))
{
xDir = "right";
}
}
} if (xDir == "right")
{
xPos = xPos + BallSpeed;
}
else
{
if (xDir == "left")
{
xPos = xPos - BallSpeed;
}
else
{
xPos = xPos;
}
}
if (yDir == "down")
{
if (yPos > (yMax - ballHeight - BallSpeed))
{
yDir = "up";
}
}
else
{
if (yDir == "up")
{
if (yPos < (0 + BallSpeed))
{
yDir = "down";
}
}
} if (yDir == "down")
{
yPos = yPos + BallSpeed;
}
else
{
if (yDir == "up")
{
yPos = yPos - BallSpeed;
}
else
{
yPos = yPos;
}
}
}
*/
function calculatePosition()
{
switch (xDir)
{
case "right":
if (xPos > (xMax - ballWidth - BallSpeed))
{
xDir = "left";
}
xPos = xPos + BallSpeed;
break; case "left":
if (xPos < (0 + BallSpeed))
{
xDir = "right";
}
xPos = xPos - BallSpeed;
break;
} switch (yDir)
{
case "down":
if (yPos > (yMax - ballHeight - BallSpeed))
{
yDir = "up";
}
yPos = yPos + BallSpeed;
break;
case "up":
if (yPos < (0 + BallSpeed))
{
yDir = "down";
}
yPos = yPos - BallSpeed;
break;
}
}
//if (document.all||document.layers)
//window.onload = InitBall;
//window.onresize = new Function("window.location.reload()");
//temp();
//设置下面一些参数,小球移动速度1-50,数值大速度快;
var ballWidth1 = 40;
var ballHeight1 = 40;
var BallSpeed1 = 2;var maxBallSpeed1 = 50;
var xMax2;
var yMax2;
var xPos2 = 500;
var yPos2 = 0;var xDir2 = "left"; //水平方向向左移动
var yDir2 = "down"; //垂直方向向下移动
var superballRunning2 = true;
var tempBallSpeed1;
var currentBallSrc2;
var newxDir2;
var newyDir2;
function moveBall2()
{
if (superballRunning2==true)
{
calculatePosition1();
if (document.all)
{
document.all("superball2").style.left = xPos2 + document.body.scrollLeft;
document.all("superball2").style.top = yPos2 + document.body.scrollTop;
}
else
{
if (document.layers)
{
document.layers["superball2"].left = xPos2 + pageXOffset;
document.layers["superball2"].top = yPos2 + pageYOffset;
}
}
setTimeout('moveBall2()',30);
}
}
function calculatePosition1()
{
if (xDir2 == "left")
{
if (xPos2 < (BallSpeed1))
{
xDir2 = "right";
}
}
else
{
if (xDir2 == "right")
{
if (xPos2 > (xMax2 - ballWidth1 - BallSpeed1))
{
xDir2 = "left";
}
}
} if (yDir2 == "down")
{
if (yPos2 > (yMax2 - ballHeight1 - BallSpeed1))
{
yDir2 = "up";
}
}
else
{
if (yDir2 == "up")
{
if (yPos2 < (0 + BallSpeed1))
{
yDir2 = "down";
}
}
} if (xDir2 == "right")
{
xPos2 = xPos2 + BallSpeed1;
}
else
{
if (xDir2 == "left")
{
xPos2 = xPos2 - BallSpeed1;
}
else
{
xPos2 = xPos2;
}
} if (yDir2 == "down")
{
yPos2 = yPos2 + BallSpeed1;
}
else
{
if (yDir2 == "up")
{
yPos2 = yPos2 - BallSpeed1;
}
else
{
yPos2 = yPos2;
}
}
}function prog()
{
InitBall();
InitBall2();
//temp();
}
//-->
</script><style type="text/css">
#superball
{
position:absolute;
left:0;
top:0;
visibility:hidden;
width:40;
height:40;
}#superball2
{
position:absolute;
left:0;
top:0;
visibility:hidden;
width:40;
height:40;
}
</style></HEAD>
<BODY aLink=#000000 bgColor=#ffffff leftMargin=0 link=#000000 text=#000000 topMargin=0 vLink=#000000 marginheight="0" marginwidth="0" onload="prog();">
<div ID="superball">
<a href="#" onClick="window.open('./floating/高考必胜/高考必胜.htm','','left=200,top=200,width=600,height=500,scrollbars=yes,resizable=no')">superball
<img src="./floating/高考必胜/gaokaobisheng.jpg" name="superballImage" width="157" height="232" border="0">
</a>
</div><div ID="superball2">
<a href="#" onClick="window.open('floating1.asp','','left=200,top=200,width=600,height=500,scrollbars=yes,resizable=no')">superball2
<img name="superballImage" src="./floating/indeximage.jpg" border="0" width="100" height="120">
</a>
</div>
</BODY>
</HTML>