Twitter Bootstrap Modal scrolling the page up on show

前端 未结 6 987
日久生厌
日久生厌 2020-12-09 12:12

Clicking on a link which triggers a Twitter Bootstrap Modal to pop up is causing the browser to scroll up the page. This behavior is only occurring in Chrome.

Here

6条回答
  •  一整个雨季
    2020-12-09 12:41

    I had a similar issue on my site, which was caused by another jquery plugin (sidr). When the sidebar was present and I opened a modal window, I would be sent back to top.

    In jquery.sidr.js I changed line 102-106 from:

    // Prepare page if container is body
    if($body.is('body')){
    scrollTop = $html.scrollTop();
    $html.css('overflow-x', 'hidden').scrollTop(scrollTop);
    }
    

    To:

    // Prepare page if container is body
    if($body.is('body') && !$('#modal').hasClass('in')){
    scrollTop = $html.scrollTop();
    $html.css('overflow-x', 'hidden').scrollTop(scrollTop);
    }
    

    If you are using this plugin along with twitter bootstrap's modal, maybe this can help you.

提交回复
热议问题