如何捕捉滚动事件?
我想实现无限滚动。 以下是我的布局的简短forms。 由于我有一些相对定位的元素,因此javascript滚动事件不会触发。
我怎样才能解决这个问题,以便触发滚动事件并实现无限滚动?
我的主要布局是:
... ...
我的CSS是:
#container { position: absolute; z-index: 1; top: 0; bottom: 35px; left: 0; right: 0; overflow-y: auto; overflow-x: hidden; } .wrapper { margin: 0 auto; width: 960px; position: relative; } #header { position: relative; } #main { } #footer { z-index: 2; position: absolute; bottom: 0; left: 0; right: 0; height: 35px; }
我需要更改什么才能使用我的布局接收浏览器滚动事件以实现无限滚动?
实现它的正确方法是:
编辑:因为你用jquery标记你的问题…
使用jQuery触发滚动事件…
HTML:
CONTENT
jQuery的:
$(document).ready(function() { $('#container').scroll(function() { alert('scroll'); // presumably your infinite scrolling code here }); });
请参阅: http : //api.jquery.com/scroll/
这是我在我的代码中使用的…
my content here
function如下
function Onscrollfnction() { var div = document.getElementById('DataDiv'); div.scrollLeft; return false; };
内容越过400px后,滚动将开始并将是无限的…享受