Change the scrollbar speed upon mouse scroll

痞子三分冷 提交于 2019-12-01 06:34:39

问题


Is it possible to change the scrollsbars speed upon scrolling using the mouse wheel for a element in JavaScript?


回答1:


You could do something like this:

http://jsfiddle.net/V3aaN/2/ (Edit: May cause seizures or epilepsy)

CSS:

#smallBox {
    height:400px;
    overflow-y:scroll;
}
#whee {
    height:20000px;
}

HTML:

    <div id="smallbox">
        <div id="whee"></div>
    </div>

JS:

    var thing = $('#smallBox');
    var extra = 100;
    var old = $(thing).scrollTop();
    $(thing).scroll(function() {
        if ($(thing).scrollTop() < old) {
            $(thing).scrollTop($(thing).scrollTop()-extra);
        } else if ($(thing).scrollTop() > old) {
            $(thing).scrollTop($(thing).scrollTop()+extra);
        }
        old = $(thing).scrollTop();
    });


来源:https://stackoverflow.com/questions/15407918/change-the-scrollbar-speed-upon-mouse-scroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!