劫持Windows滚动条

时间:2011-02-14 21:33:46

标签: javascript html

这可能看起来像一个奇怪的问题,但我需要知道是否有可能劫持窗口滚动条,所以当用户滚动它时它不会滚动页面。我想写一些js,而当用户滚动窗口滚动条时,它会滚动一个div。我可以写js来检测滚动和动画div等多少,但不知道如何劫持窗口滚动条并停止滚动窗口这可能吗?

1 个答案:

答案 0 :(得分:5)

您可以尝试其他一些方法,而不是尝试“劫持”浏览器窗口,例如:

< - 溢出------------------------------------------- --------->

[CSS]:

<style>
html, body {
    overflow: none;
}
</style>

[JavaScript的]:

<script>
window.addEventListener('DOMMouseScroll', onScroll, false);
window.onmousewheel = function onScroll(event) {
    // Use "event" to distinguish between up or down
    // for which you determine which way to scroll
    // the particular div you want.
}
</script>


&lt; - 防止违约---------------------------------------&gt; < / H1>

[javascript(未经测试)]:

<script>
window.addEventListener('DOMMouseScroll', onMouseWheel, false);
window.onmousewheel = document.onmousewheel = onMouseWheel; // IE

function onMouseWheel(event) {
    event.stopPropagation();
    event.preventDefault();
    event.cancelBubble = true;

        // Use "event" to distinguish between up or down
        // for which you determine which way to scroll
        // the particular div you want.

    return false;
}
</script>