Scrolling within a div without moving page

后端 未结 5 1507
忘了有多久
忘了有多久 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条回答
  •  庸人自扰
    2020-12-19 20:34

    I just solved my issue with this by creating the following in CSS:

    body.scroll_locked {
        height: 100%;
        width: 100%;
        overflow: hidden;
    }
    

    Then, when I show my modal/lightbox, which is JavaScript (jQuery), I add the scroll_locked class to the body to lock it in place and remove the class to go back. Seems like you could do the same for a mouseenter/mouseleave event for a div that's always on the page and you want to have the same effect.

    $('body').addClass('scroll_locked');
    $('body').removeClass('scroll_locked');
    

提交回复
热议问题