【发布时间】:2012-11-19 23:29:23
【问题描述】:
我如何才能在 div 之外滚动,并且在我的情况下,动作将被分配给具有隐藏溢出的固定 div 是#scrollable_content。
HTML
<div id="container">
<div id="header">Header</div>
<div id="scrollable_content">
Very long content<br />
Very long content<br />
...
Very long content<br />
Very long content<br />
</div>
<div id="footer">Footer</div>
CSS
html, body {
height:100%;
margin: 0;
padding: 0;
overflow: hidden;
}
div { margin: 0; padding: 0;}
div#header{position:absolute;top:0;width:100%;border:1px solid black;}
div#footer{position:absolute; bottom:0; width:100%; border:1px solid black;}
div#scrollable_content {
height: 300px;
overflow-y:auto;
position: static;
border: 1px solid green;
margin: 150px;
}
【问题讨论】:
-
澄清一下,如果用户在页面上的任意位置滚动鼠标滚轮,而不仅仅是在 div 上方,您希望 #scrollable_content 滚动?
-
你说的是javascript事件吗,比如$('#scrollable_conten').on('scroll', function(){...})?
-
是的,在页面上并使用 jquery
-
应该类似于 $('body')....
-
是的,但是问题 scoll 事件只有在页面实际 scolling 时才会触发,否则不会
标签: javascript jquery html css scroll