Scrolling within a div without moving page

后端 未结 5 1496
忘了有多久
忘了有多久 2020-12-19 19:46

I have a

with overflow-y:scroll;. Links to anchors within innerContent are located on parent page, not in the
5条回答
  •  旧时难觅i
    2020-12-19 20:14

    This jsfiddle works in Chrome for me. Not tested in other browsers.

    Catches the mousewheel event, uses the event data to scroll manually, then cancels the original event. Seems potentially messy for production.

    $('#scroll').bind('mousewheel', function(e){
    
        $(this).scrollTop($(this).scrollTop()-e.originalEvent.wheelDeltaY);
    
        //prevent page fom scrolling
        return false;    
    });
    

提交回复
热议问题