Scroll.js用于#bird块,它跟随页面滚动。

主要问题 - 它正在工作,如果我删除Doctype行,这个:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
如果启用了doctype,则

无效。

这是html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <script src="jquery.js" type="text/javascript"></script>
    <script src="scroll.js" type="text/javascript"></script>
</head>

<body>
<div style="position:relative; height:20000px">
    <div id="bird" style="position:absolute;left:0;top:20px;width:200px"></div>     
</div>
</body>
</html>

和js:

  

除去

请勿删除 doctype,

有帮助吗?

解决方案

你需要替换它:

document.body.scrollTop

用这个:

document.documentElement.scrollTop

scrollTop属于标准模式中的<html>元素,而不是<body>元素。

(请注意document.body.scrollTop在您的代码中出现三次。)

其他提示

你的鸟类div有一个问题,风格有宽度:200 <!>,应该是宽度:200px <!>“; (添加单位)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top