Prevent parent scroll when in child div

后端 未结 5 1559
野的像风
野的像风 2021-02-08 12:08

When I scroll to the bottom of the child div, the body element starts scrolling.

How can I prevent this? I only want the body to s

5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-08 12:57

    By adding some javascript of course!

    FIDDLE

    $( '.area' ).on( 'mousewheel', function ( e ) {
        var event = e.originalEvent,
            d = event.wheelDelta || -event.detail;
    
        this.scrollTop += ( d < 0 ? 1 : -1 ) * 30;
        e.preventDefault();
    });
    

提交回复
热议问题