1

我目前正在尝试在滚动处于某个垂直值时更改 div 的颜色。虽然目前我的滚动似乎没有检测到页面顶部或底部之间的任何内容。

因此,当我点击页面底部时,我会看到 0、1、2、3、4、5 等,而当我点击页面顶部时,它会出现 0、-1、-2、-3 等。所以似乎有在页面的顶部和底部之间没有页面,因为除了页面的顶部或底部之外,不会在任何地方触发滚动。

HTML结构:

<body>
    <div id="container">  
         <div id="post-view">
             <div id="cover-image">
                 <header>
                     <div class="title">
                     </div>
                     <div class="sub-title">
                     </div>
                 </header>                 
             </div>
         </div>
         <div class="suggested">
             content in here
         </div>
    </div>
</body>

jQuery:

$(document).scroll(function() {
    var y = $(this).scrollTop();
    console.log(y);
});

CSS:

html, body{
height:100%;
width:100%;
background: #ffffff !important;
overflow-x: hidden;
margin:0;
}

header{
width:100%;
border-bottom: 1px solid #cccccc;
background: #333333;
overflow:hidden;
padding:10px 0 0 0 ;
}

#container{
width:100%;
}

非常感谢任何帮助,如果您需要更多信息,请发表评论。谢谢!

4

2 回答 2

2

正如你在上面看到的,我在我的 CSS 中有html, body { height:100% }这是罪魁祸首。真的很奇怪。现在可以工作了。谢谢你的时间。

于 2014-01-30T18:47:50.300 回答
0

制作一个 2k px 高的元素以知道它会滚动。h2 告诉你它滚动了多远。作品?

http://cdpn.io/oHACi

于 2014-01-30T17:15:42.560 回答