javascript 脚本漂浮的广告为什么不会动?请高手指点

bxjingang008 2009-12-05 11:35:56
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
var advInitTop=0;
function init()
{
x=document.getElementById("advLayer").style.pixelTop;
}
function move(){
document.getElementById("advLayer").style.pixelTop=advInitTop+document.body.scrollTop;

}
window.onscroll=move;
</script>
</head>

<body onload="init()">
<div id="advLayer" style ="position:absolute;left:16px;top:129px;width:180px;height:230px;z-index:1;"><img src="images/advpic.gif" width="180" height="230"></div>



<img src="images/contentpic.jpg" width="993" height="1799">

</body>
</html>
...全文
148 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
gaonisihu 2010-04-18
  • 打赏
  • 举报
回复
我和你说我们看的是一样的书!问题一样!上面的那个大兄弟说的很对!
bxjingang008 2009-12-06
  • 打赏
  • 举报
回复
哦 谢谢了拜拜
crazylaa 2009-12-06
  • 打赏
  • 举报
回复
嗯,书上可能没有最上面的
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
这句话吧?
如果有还这么写,那就不知道为什么了。
bxjingang008 2009-12-06
  • 打赏
  • 举报
回复
谢谢看到了 document.documentElement.scrollTop
这句话就是获取滚动条到文档上方的距离

书上还是document.body.scrollTop;
crazylaa 2009-12-06
  • 打赏
  • 举报
回复
不一样,你看这里面的
parseInt(document.documentElement.scrollTop);
你的是
document.body.scrollTop;
bxjingang008 2009-12-06
  • 打赏
  • 举报
回复
你只是做了转换数据类型
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">

这段代码和我的一样啊
crazylaa 2009-12-06
  • 打赏
  • 举报
回复
如果顶部申明

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">

document.body.scrollTop
要改成
document.documentElement.scrollTop

这样就没问题。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script language="javascript">
var advInitTop=0;
function init()
{
x=document.getElementById("advLayer").style.pixelTop;
}
function move(){
document.getElementById("advLayer").style.pixelTop=parseInt(advInitTop)+ parseInt(document.documentElement.scrollTop);
}
window.onscroll=move;
</script>
</head>

<body onload="init()">
<div id="advLayer" style ="position:absolute;left:16px;top:129px;width:180px;height:230px;z-index:1;"> <img src="images/advpic.gif" width="180" height="230"> </div>


<img src="images/contentpic.jpg" width="993" height="1799">

</body>
</html>

51,409

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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