Smooth horizontal scroll bound to mousewheel

后端 未结 7 636
星月不相逢
星月不相逢 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条回答
  •  时光取名叫无心
    2020-12-29 12:59

    I found other nice solution - to use wrapper, so you scroll absolute to same position as you would to scroll vertical, it works if you just need scroll, no text selection or other(may be can work arounded, but i tired)

    $(function() {
    
        var scroll = $('.scrollme');
        var h = scroll.parent().height();
        var w = scroll.parent().width();
        var t = scroll.offset().top;
        var l = scroll.offset().left;
        var vertscroll_wrap = $("
    ").height(h).width(10000).css('position', 'absolute').css('top', t).css('left', l).css('z-index', 10000).css('opacity', 0.5).css('overflow-y', 'scroll');     var vertscroll = $('
    ').height(10000).css('width', '100%').css('opacity', 0.5);     vertscroll_wrap.append(vertscroll);     $('body').append(vertscroll_wrap); vertscroll_wrap.height('100%');     vertscroll_wrap.scroll(function() {         $(scroll).parent().scrollLeft($(this).scrollTop());     }); });​

    http://jsfiddle.net/oceog/Dw4Aj/16/

    i made another sample, now without wholescreen wrapper, and possibility to select http://jsfiddle.net/oceog/DcyWD/

提交回复
热议问题