这个网页应该有一个柠檬掉落和弹跳,但我发现自己犯了错误,我找不到它们
This web page is supposed to have a lemon dropping and bouncing but I seam to have made mistakes and I can not find them
这是代码。
我认为主要的问题只是我看不见的东西,因为我盯着它看太久了。我一直在研究它的逻辑,看起来一切都很好,但我知道我一定在某个地方犯了一些错误(我猜错误大多在第二个脚本中,而不是第一个。
<SCRIPT LANGUAGE="JavaScript1.2">
<!-- Begin
function BrowserCheck() {
var b = navigator.appName;
if (b == "Netscape") this.b = "NS";
else if (b == "Microsoft Internet Explorer") this.b = "IE";
else this.b = b;
this.v = parseInt(navigator.appVersion);
this.NS = (this.b == "NS" && this.v>=4);
this.NS4 = (this.b == "NS" && this.v == 4);
this.NS5 = (this.b == "NS" && this.v == 5);
this.IE = (this.b == "IE" && this.v>=4);
this.IE4 = (navigator.userAgent.indexOf('MSIE 4')>0);
this.IE5 = (navigator.userAgent.indexOf('MSIE 5')>0);
if (this.IE5 || this.NS5) this.VER5 = true;
if (this.IE4 || this.NS4) this.VER4 = true;
this.OLD = (! this.VER5 && ! this.VER4) ? true : false;
this.min = (this.NS||this.IE);
}
is = new BrowserCheck();
// End -->
</script>
</HEAD>
<BODY>
<center>
Click on the screen to drop lemon<br>
<div id="staticBall" style="position:relative;visibility:visible">
<img src="lemon.png" height=30 width=30 alt="Static lemon">
</div>
</center>
<div id="ball" style="visibility:hidden; position:absolute; left:100; top:10; height:34; width:34">
<img src="lemon.png" height=30 width=30 alt="Bouncing lemon">
</div>
<script language="Javascript1.2">
<!-- Begin
iter = 0;
setId = 0;
down = true;
up = false;
bouncingBall = (is.VER5) ? document.getElementId("ball").style
: (is.NS) ? document.layers["ball"]
: document.all["ball"].style;
stillBall = (is.VER5) ? document.getElementId("staticBall").style
: (is.NS) ? document.layers["staticBall"] : document.all["staticBall"].style;
winH = (is.NS) ? window.innerHeight - 55 : document.body.offsetHeight - 55;
document.onmouseup = buttonUp;
if (is.NS4)
document.captureEvents(Event.MOUSEUP);
function buttonUp(e) {
if ( ((is.NS) ? e.which : event.button) != 1) return true;
if (setId != 0) clearInterval(setId);
bouncingBall.visibility="visible";
stillBall.visibility="hidden";
bouncingBall.left = (is.NS) ? e.pageX - 15 : event.offsetX - 15;
bouncingBall.top = (is.NS) ? e.pageY - 15 : event.offsetY - 15;
iter = 0;
setId = setInterval("generateGravity()", 20);
return true;
}
function generateGravity {
if ((parseInt(bouncingBall.top)+iter < winH) && down) {
bouncingBall.top = parseInt(bouncingBall.top) + iter;
iter++;
return;
}
else {
if ((parseInt(bouncingBall.top)< winH) && down) {
bouncingBall.top = winH + 5;
return;
}
down = false;
up = true;
if (iter < 0 && parseint(bouncingBall.top) > winH) {
clearInterval(setId);
bouncingBall.visibility = "hidden";
stillBall.visibility="visible";
setId = 0;
}
if (parseInt(bouncingBall.top) > 0 && up && iter >= 0) {
bouncingBall.top = parseint(bouncingBall.top) - iter;
iter--;
if (iter%3 == 0) iter--;
return;
}
down = true;
up = false;
}
}
// End -->
</script>
<p><center>
</center><p>
</BODY>
</HTML>
您使用的是浏览器可能没有使用的旧版本的javascript。
当我把控制台复制到我的机器上时,它出现了两个错误。
Uncaught SyntaxError: Unexpected token {
file:///home/tkrg/lemon.png Failed to load resource: net::ERR_FILE_NOT_FOUND
对于第一个错误,()似乎不是为函数编写的。上面写着
function generateGravity {
应该说
function generateGravity() {
对于第二个错误,我认为可以放心地假设你有柠檬的照片。
还有两件事不起作用:
parseint()
现在是
parseInt()
这个:
getElementId()
现在是
getElementById()
完整代码
<SCRIPT>
function BrowserCheck() {
var b = navigator.appName;
if (b == "Netscape") this.b = "NS";
else if (b == "Microsoft Internet Explorer") this.b = "IE";
else this.b = b;
this.v = parseInt(navigator.appVersion);
this.NS = (this.b == "NS" && this.v>=4);
this.NS4 = (this.b == "NS" && this.v == 4);
this.NS5 = (this.b == "NS" && this.v == 5);
this.IE = (this.b == "IE" && this.v>=4);
this.IE4 = (navigator.userAgent.indexOf('MSIE 4')>0);
this.IE5 = (navigator.userAgent.indexOf('MSIE 5')>0);
if (this.IE5 || this.NS5) this.VER5 = true;
if (this.IE4 || this.NS4) this.VER4 = true;
this.OLD = (! this.VER5 && ! this.VER4) ? true : false;
this.min = (this.NS||this.IE);
}
is = new BrowserCheck();
</script>
</HEAD>
<BODY>
<center>
Click on the screen to drop lemon<br>
<div id="staticBall" style="position:relative;visibility:visible">
<img src="lemon.png" height=30 width=30 alt="Static lemon">
</div>
</center>
<div id="ball" style="visibility:hidden; position:absolute; left:100; top:10; height:34; width:34">
<img src="lemon.png" height=30 width=30 alt="Bouncing lemon">
</div>
<script>
iter = 0;
setId = 0;
down = true;
up = false;
bouncingBall = (is.VER5) ? document.getElementById("ball").style
: (is.NS) ? document.layers["ball"]
: document.all["ball"].style;
stillBall = (is.VER5) ? document.getElementById("staticBall").style
: (is.NS) ? document.layers["staticBall"] : document.all["staticBall"].style;
winH = (is.NS) ? window.innerHeight - 55 : document.body.offsetHeight - 55;
document.onmouseup = buttonUp;
if (is.NS4)
document.captureEvents(Event.MOUSEUP);
function buttonUp(e) {
if ( ((is.NS) ? e.which : event.button) != 1) return true;
if (setId != 0) clearInterval(setId);
bouncingBall.visibility="visible";
stillBall.visibility="hidden";
bouncingBall.left = (is.NS) ? e.pageX - 15 : event.offsetX - 15;
bouncingBall.top = (is.NS) ? e.pageY - 15 : event.offsetY - 15;
iter = 0;
setId = setInterval("generateGravity()", 20);
return true;
}
function generateGravity() {
if ((parseInt(bouncingBall.top)+iter < winH) && down) {
bouncingBall.top = parseInt(bouncingBall.top) + iter;
iter++;
return;
}
else {
if ((parseInt(bouncingBall.top)< winH) && down) {
bouncingBall.top = winH + 5;
return;
}
down = false;
up = true;
if (iter < 0 && parseInt(bouncingBall.top) > winH) {
clearInterval(setId);
bouncingBall.visibility = "hidden";
stillBall.visibility="visible";
setId = 0;
}
if (parseInt(bouncingBall.top) > 0 && up && iter >= 0) {
bouncingBall.top = parseInt(bouncingBall.top) - iter;
iter--;
if (iter%3 == 0) iter--;
return;
}
down = true;
up = false;
}
}
</script>
<p><center>
</center><p>
</BODY>
</HTML>
相关文章:
- 如何通过自己获得Chrome扩展的用户反馈/错误报告
- 按我自己的类克隆另一个元素的内容和顺序
- 如何配置分析以将数据发送到我自己的服务器
- 如何使用jquery ajax和jsonp在您自己的域上读取json数据
- javascript从任何嵌入式flash视频中发现.flvurl
- 创造自己的智能
- 用于发现哪个JS/jQuery脚本正在冻结页面的工具或技术
- 让自己在文章中成为社交明星's内容高度
- 如何在Win8Metro应用程序的Javascript代码中捕获自己的C#事件
- 从自己的安全系统中重新找回自己
- 我需要一个jQuery函数来只工作在700px以上的屏幕大小,无法在我的代码中发现错误
- 我发现了一些只在移动设备上可见的垃圾邮件链接,我可以'找不到包含此垃圾邮件链接的脚本的位置
- 麻烦将coffee脚本片段移动到rails中自己的类中
- 试图创建一个24小时计时器来重置自己
- 从我自己的脚本中包含的Javascript文件中调用一个函数
- 让我自己的过滤器不工作
- 如何在Node.js控制台中发现Object API
- 这个网页应该有一个柠檬掉落和弹跳,但我发现自己犯了错误,我找不到它们
- 是否有一种方法可以发现javascript 6类是否定义了自己的构造函数?
- 我发现自己在使用Backbone.js或其他MVC时重复了很多代码