Smooth horizontal scroll bound to mousewheel

后端 未结 7 637
星月不相逢
星月不相逢 2020-12-29 12:08

Here is a working example of horizontal scroll with mousewheel, but it does not scroll smoothly. By smoothly I mean like ordinary vertical scroll in Firefox or Opera.

<
7条回答
  •  -上瘾入骨i
    2020-12-29 12:47

    Try to use your function in conjunction with .animate()

    $(function() {
        $("html, body").mousewheel(function(event, delta) {
            var scroll_distance = delta * 30
            this.animate(function(){
               left: "-=" + scroll_distance + "px",
            });
            event.preventDefault();
        });
    });
    

    I just actually did this myself and it works. I created an instagram feed on the web application that I created, and the other plugins that I was using were breaking all too often:

    $('#add_instagram').on('mousewheel', function(e,d){
        var delta = d*10;
        $('#move_this').animate({
            top: "-=" + delta + "px"
        },3);
        e.preventDefault();
    });
    

提交回复
热议问题