Change the scrollbar speed upon mouse scroll

前端 未结 1 366
我寻月下人不归
我寻月下人不归 2021-01-14 09:52

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

相关标签:
1条回答
  • 2021-01-14 10:21

    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();
        });
    
    0 讨论(0)
提交回复
热议问题