找回密码

碧海潮声大学生网

查看: 962|回复: 6
打印 上一主题 下一主题

[求助]====每日一帖,我的网页论坛首页怎么有错误

[复制链接]
跳转到指定楼层
1#
发表于 2005-11-8 11:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我下载了笨笨给的漂浮广告代码

以下是他的代码
  1. <SCRIPT LANGUAGE="JavaScript">
  2. <!-- Begin
  3. var isNS = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4));
  4. var _all = &#39;&#39;;
  5. var _style = &#39;&#39;;
  6. var wwidth, wheight;
  7. var ydir = &#39;++&#39;;
  8. var xdir = &#39;++&#39;;
  9. var id1, id2, id3;
  10. var x = 1;
  11. var y = 1;
  12. var x1, y1;
  13. if(!isNS) {
  14. _all=&#39;all.&#39;;
  15. _style=&#39;.style&#39;;
  16. }
  17. function getwindowsize() {
  18. clearTimeout(id1);
  19. clearTimeout(id2);
  20. clearTimeout(id3);
  21. if (isNS) {
  22. wwidth = window.innerWidth - 55;
  23. wheight = window.innerHeight - 50;
  24. } else {
  25. wwidth = document.body.clientWidth - 55;
  26. wheight = document.body.clientHeight - 50;
  27. }
  28. id3 = setTimeout(&#39;randomdir()&#39;, 20000);
  29. animate();
  30. }
  31. function randomdir() {
  32. if (Math.floor(Math.random()*2)) {
  33. (Math.floor(Math.random()*2)) ? xdir=&#39;--&#39;: xdir=&#39;++&#39;;
  34. } else {
  35. (Math.floor(Math.random()*2)) ? ydir=&#39;--&#39;: ydir=&#39;++&#39;;
  36. }
  37. id2 = setTimeout(&#39;randomdir()&#39;, 20000);
  38. }
  39. function animate() {
  40. eval(&#39;x&#39;+xdir);
  41. eval(&#39;y&#39;+ydir);
  42. if (isNS) {
  43. pic1.moveTo((x+pageXOffset),(y+pageYOffset))
  44. } else {
  45. pic1.pixelLeft = x+document.body.scrollLeft;
  46. pic1.pixelTop = y+document.body.scrollTop;
  47. }
  48. if (isNS) {
  49. if (pic1.top <= 5+pageYOffset) ydir = &#39;++&#39;;
  50. if (pic1.top >= wheight+pageYOffset) ydir = &#39;--&#39;;
  51. if (pic1.left >= wwidth+pageXOffset) xdir = &#39;--&#39;;
  52. if (pic1.left <= 5+pageXOffset) xdir = &#39;++&#39;;
  53. } else {
  54. if (pic1.pixelTop <= 5+document.body.scrollTop) ydir = &#39;++&#39;;
  55. if (pic1.pixelTop >= wheight+document.body.scrollTop) ydir = &#39;--&#39;;
  56. if (pic1.pixelLeft >= wwidth+document.body.scrollLeft) xdir = &#39;--&#39;;
  57. if (pic1.pixelLeft <= 5+document.body.scrollLeft) xdir = &#39;++&#39;;
  58. }
  59. id1 = setTimeout(&#39;animate()&#39;, 30);
  60. }
  61. //  End -->
  62. </script>
  63. <style type="text/css">
  64. <!--
  65. .style1 {color: #FF0000}
  66. -->
  67. </style>
  68. </head>
  69. <LINK
  70. href="css.css" type=text/css rel=stylesheet>
  71. <div id="pic1" style="position:absolute; visibility:visible; left:0px; top:0px; z-index:1">
  72. <a href="wish.php" target=_blank><img src="image/wish.gif" border=0></a>
  73. </div>
  74. <script language="javascript">
  75. var pic1=eval(&#39;document.&#39;+_all+&#39;pic1&#39;+_style);
  76. </script>
  77. </head>
  78. <BODY leftMargin=0 topMargin=0 background="01img/bg01.jpg" onLoad="getwindowsize()" OnResize="getwindowsize()">
  79. </body>
  80. <style type="text/css">
  81. #floater {
  82. position: absolute;
  83. left: 500;
  84. top: 146;
  85. width: 125;
  86. visibility: visible;
  87. z-index: 10;
  88. }</style>
  89. <!-- <div ID="floater" style="left: 0px; top: 300px">
  90. <p align="center">
  91. <img SRC="01img\left.gif" border="0">
  92. </div> --><script LANGUAGE="JavaScript">
  93. self.onError=null;
  94. currentX = currentY = 0;
  95. whichIt = null;
  96. lastScrollX = 0; lastScrollY = 0;
  97. NS = (document.layers) ? 1 : 0;
  98. IE = (document.all) ? 1: 0;
  99. <!-- STALKER CODE -->
  100. function heartBeat() {
  101. if(IE) { diffY = document.body.scrollTop; diffX = document.body.scrollLeft; }
  102. if(NS) { diffY = self.pageYOffset; diffX = self.pageXOffset; }
  103. if(diffY != lastScrollY) {
  104. percent = .1 * (diffY - lastScrollY);
  105. if(percent > 0) percent = Math.ceil(percent);
  106. else percent = Math.floor(percent);
  107. if(IE) document.all.floater.style.pixelTop += percent;
  108. if(NS) document.floater.top += percent;
  109. lastScrollY = lastScrollY + percent;
  110. }
  111. if(diffX != lastScrollX) {
  112. percent = .1 * (diffX - lastScrollX);
  113. if(percent > 0) percent = Math.ceil(percent);
  114. else percent = Math.floor(percent);
  115. if(IE) document.all.floater.style.pixelLeft += percent;
  116. if(NS) document.floater.left += percent;
  117. lastScrollX = lastScrollX + percent;
  118. }
  119. }
  120. <!-- /STALKER CODE -->
  121. <!-- DRAG DROP CODE -->
  122. function checkFocus(x,y) {
  123. stalkerx = document.floater.pageX;
  124. stalkery = document.floater.pageY;
  125. stalkerwidth = document.floater.clip.width;
  126. stalkerheight = document.floater.clip.height;
  127. if( (x > stalkerx && x < (stalkerx+stalkerwidth)) && (y > stalkery && y < (stalkery+stalkerheight))) return true;
  128. else return false;
  129. }
  130. function grabIt(e) {
  131. if(IE) {
  132. whichIt = event.srcElement;
  133. while (whichIt.id.indexOf("floater") == -1) {
  134. whichIt = whichIt.parentElement;
  135. if (whichIt == null) { return true; }
  136. }
  137. whichIt.style.pixelLeft = whichIt.offsetLeft;
  138. whichIt.style.pixelTop = whichIt.offsetTop;
  139. currentX = (event.clientX + document.body.scrollLeft);
  140. currentY = (event.clientY + document.body.scrollTop);  
  141. } else {
  142. window.captureEvents(Event.MOUSEMOVE);
  143. if(checkFocus (e.pageX,e.pageY)) {
  144. whichIt = document.floater;
  145. StalkerTouchedX = e.pageX-document.floater.pageX;
  146. StalkerTouchedY = e.pageY-document.floater.pageY;
  147. }
  148. }
  149. return true;
  150. }
  151. function moveIt(e) {
  152. if (whichIt == null) { return false; }
  153. if(IE) {
  154. newX = (event.clientX + document.body.scrollLeft);
  155. newY = (event.clientY + document.body.scrollTop);
  156. distanceX = (newX - currentX);   distanceY = (newY - currentY);
  157. currentX = newX;   currentY = newY;
  158. whichIt.style.pixelLeft += distanceX;
  159. whichIt.style.pixelTop += distanceY;
  160. if(whichIt.style.pixelTop < document.body.scrollTop) whichIt.style.pixelTop = document.body.scrollTop;
  161. if(whichIt.style.pixelLeft < document.body.scrollLeft) whichIt.style.pixelLeft = document.body.scrollLeft;
  162. if(whichIt.style.pixelLeft > document.body.offsetWidth - document.body.scrollLeft - whichIt.style.pixelWidth - 20) whichIt.style.pixelLeft = document.body.offsetWidth - whichIt.style.pixelWidth - 20;
  163. if(whichIt.style.pixelTop > document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5) whichIt.style.pixelTop = document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5;
  164. event.returnValue = false;
  165. } else {
  166. whichIt.moveTo(e.pageX-StalkerTouchedX,e.pageY-StalkerTouchedY);
  167. if(whichIt.left < 0+self.pageXOffset) whichIt.left = 0+self.pageXOffset;
  168. if(whichIt.top < 0+self.pageYOffset) whichIt.top = 0+self.pageYOffset;
  169. if( (whichIt.left + whichIt.clip.width) >= (window.innerWidth+self.pageXOffset-17)) whichIt.left = ((window.innerWidth+self.pageXOffset)-whichIt.clip.width)-17;
  170. if( (whichIt.top + whichIt.clip.height) >= (window.innerHeight+self.pageYOffset-17)) whichIt.top = ((window.innerHeight+self.pageYOffset)-whichIt.clip.height)-17;
  171. return false;
  172. }
  173. return false;
  174. }
  175. function dropIt() {
  176. whichIt = null;
  177. if(NS) window.releaseEvents (Event.MOUSEMOVE);
  178. return true;
  179. }
  180. <!-- DRAG DROP CODE -->
  181. if(NS) {
  182. window.captureEvents(Event.MOUSEUP|Event.MOUSEDOWN);
  183. window.onmousedown = grabIt;
  184. window.onmousemove = moveIt;
  185. window.onmouseup = dropIt;
  186. }
  187. if(IE) {
  188. document.onmousedown = grabIt;
  189. document.onmousemove = moveIt;
  190. document.onmouseup = dropIt;
  191. }
  192. if(NS || IE) action = window.setInterval("heartBeat()",1);
  193. </script>
复制代码

我把这段代码直接加到template\wind下的index.htm,在网页上会出现错误

以下错误的提示;
  1. Line:589
  2. Char:8
  3. Code:0
  4. Error:&#39;document.all.floater.style&#39; 为空或不是对象
  5. 网址:[url]http://172.16.173.250/bbs/index.php[/url]
复制代码

现在我把index.htm文件传上来,请大家看一下,错在了哪里?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩
2#
发表于 2005-11-8 12:19 | 只看该作者
哈哈,后面那段删掉
当时发错了
3#
发表于 2005-11-8 12:20 | 只看该作者
只保留
  1. <SCRIPT LANGUAGE="JavaScript">
  2. <!-- Begin
  3. var isNS = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4));
  4. var _all = &#39;&#39;;
  5. var _style = &#39;&#39;;
  6. var wwidth, wheight;
  7. var ydir = &#39;++&#39;;
  8. var xdir = &#39;++&#39;;
  9. var id1, id2, id3;
  10. var x = 1;
  11. var y = 1;
  12. var x1, y1;
  13. if(!isNS) {
  14. _all=&#39;all.&#39;;
  15. _style=&#39;.style&#39;;
  16. }
  17. function getwindowsize() {
  18. clearTimeout(id1);
  19. clearTimeout(id2);
  20. clearTimeout(id3);
  21. if (isNS) {
  22. wwidth = window.innerWidth - 55;
  23. wheight = window.innerHeight - 50;
  24. } else {
  25. wwidth = document.body.clientWidth - 55;
  26. wheight = document.body.clientHeight - 50;
  27. }
  28. id3 = setTimeout(&#39;randomdir()&#39;, 20000);
  29. animate();
  30. }
  31. function randomdir() {
  32. if (Math.floor(Math.random()*2)) {
  33. (Math.floor(Math.random()*2)) ? xdir=&#39;--&#39;: xdir=&#39;++&#39;;
  34. } else {
  35. (Math.floor(Math.random()*2)) ? ydir=&#39;--&#39;: ydir=&#39;++&#39;;
  36. }
  37. id2 = setTimeout(&#39;randomdir()&#39;, 20000);
  38. }
  39. function animate() {
  40. eval(&#39;x&#39;+xdir);
  41. eval(&#39;y&#39;+ydir);
  42. if (isNS) {
  43. pic1.moveTo((x+pageXOffset),(y+pageYOffset))
  44. } else {
  45. pic1.pixelLeft = x+document.body.scrollLeft;
  46. pic1.pixelTop = y+document.body.scrollTop;
  47. }
  48. if (isNS) {
  49. if (pic1.top <= 5+pageYOffset) ydir = &#39;++&#39;;
  50. if (pic1.top >= wheight+pageYOffset) ydir = &#39;--&#39;;
  51. if (pic1.left >= wwidth+pageXOffset) xdir = &#39;--&#39;;
  52. if (pic1.left <= 5+pageXOffset) xdir = &#39;++&#39;;
  53. } else {
  54. if (pic1.pixelTop <= 5+document.body.scrollTop) ydir = &#39;++&#39;;
  55. if (pic1.pixelTop >= wheight+document.body.scrollTop) ydir = &#39;--&#39;;
  56. if (pic1.pixelLeft >= wwidth+document.body.scrollLeft) xdir = &#39;--&#39;;
  57. if (pic1.pixelLeft <= 5+document.body.scrollLeft) xdir = &#39;++&#39;;
  58. }
  59. id1 = setTimeout(&#39;animate()&#39;, 30);
  60. }
  61. //  End -->
  62. </script>
  63. <style type="text/css">
  64. <!--
  65. .style1 {color: #FF0000}
  66. -->
  67. </style>
  68. </head>
  69. <LINK
  70. href="css.css" type=text/css rel=stylesheet>
  71. <div id="pic1" style="position:absolute; visibility:visible; left:0px; top:0px; z-index:1">
  72. <a href="wish.php" target=_blank><img src="image/wish.gif" border=0></a>
  73. </div>
  74. <script language="javascript">
  75. var pic1=eval(&#39;document.&#39;+_all+&#39;pic1&#39;+_style);
  76. </script>
  77. </head>
  78. <BODY leftMargin=0 topMargin=0 background="01img/bg01.jpg" onLoad="getwindowsize()" OnResize="getwindowsize()">
  79. </body>
  80. <style type="text/css">
  81. #floater {
  82. position: absolute;
  83. left: 500;
  84. top: 146;
  85. width: 125;
  86. visibility: visible;
  87. z-index: 10;
  88. }</style>
复制代码
这一段
4#
发表于 2005-11-8 12:38 | 只看该作者
这段代码的错误在于,floater这个对象没有定义.
呵呵,我看出来了,这段浮动效果代码,笨笨同志偷了点懒,把思政网首面上的那段代码复制下来了.而且没作什么改动.  偶曾改写过这一段,所以揪出来啦,嘿嘿
原文中有floater的定义:
  1. <!-- <div ID="floater" style="left: 0px; top: 300px">
  2. <p align="center">
  3. <img SRC="01img\left.gif" border="0">
  4. </div> -->
复制代码
笨笨只是把这段注释掉了.却忘了改JS.所以有这个错误.

如果你想实现浮动效果,把这段HTML代码的注释去掉,再把里面这个图片名换成你要显示的图片就行啦!
5#
发表于 2005-11-8 12:46 | 只看该作者
嘻嘻,是的,因为偷懒,所以就直接复制了,也没有测试-_-#因为那时太晚了,困得不得了
第二天上论坛才得知有角本错误,呵呵
6#
 楼主| 发表于 2005-11-8 21:43 | 只看该作者
晕,怪不得,总是有错误

我不发出来,一直要错下去吗
7#
发表于 2005-11-8 21:53 | 只看该作者
因为这帖子没更新嘛
我自己论坛上的是第二天就修正过来了…………
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋| 碧海潮声大学生网  

Copyright © 2001-2013 Comsenz Inc.   All Rights Reserved.

Powered by Discuz! X3.2( 浙ICP备11026473号 )

快速回复 返回顶部 返回列表