Urb*_*coz 5 html javascript scroll
我的页面上有几个div看起来像这样:
<div style="height:200px; overflow:auto;">
<div style="height:300px;">
<!--Lots of text here-->
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
当用户将鼠标悬停在它们上面并使用滚轮滚动时,它们可以正常滚动.麻烦的是,当用户到达底部时,页面本身开始滚动.
有没有办法阻止这种情况发生(必要时使用javascript),以便焦点保持在div上,即使它已经滚动到底部,页面本身只在用户没有悬停在div上时滚动?
检查这个演示:http://jsfiddle.net/zUGKW/1/
代码:
// bind the mousewheel event
$('.myDiv').bind('mousewheel', function(e) {
// if scroll direction is down and there is nothing more to scroll
if(e.originalEvent.wheelDelta < 0 &&
($(this).scrollTop() + $(this).height()) >= this.scrollHeight) return false;
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
405 次 |
| 最近记录: |