Fullpage.js: Disable scrolling when Bootstrap modal opened

Created on 13 Apr 2015  路  10Comments  路  Source: alvarotrigo/fullPage.js

Is it possible to disable scrolling of sections when a Bootstrap modal is opened? Bootstrap will add the class .modal-open to the body. Maybe we can work with that?

Thanks, r!

question

Most helpful comment

Use the option normalScrollElements for it. Read more in the docs.

All 10 comments

Use the option normalScrollElements for it. Read more in the docs.

normalScrollElements: '.modal'

(plus http://stackoverflow.com/questions/9538868/prevent-body-from-scrolling-when-a-modal-is-opened)

...did the job! Thanks for the quick reply!

Excellent @alvarotrigo ... It works like a charm...

It works like a charm when scrolling, but when modal is open and I can still scroll with arrow down and up buttons.

For the record, works fine with MDL's dialog also.

Maybe this will solve:

$('.modal').on('show.bs.modal', function () {
    $("body").css('overflow', 'hidden');
}).on("hidden", function () {
        $("body").css('overflow', 'auto');
});

it's not working on mobile devices, please can you help me !!!

That worked for me

Maybe this will solve:

$('.modal').on('show.bs.modal', function () {
  $("body").css('overflow', 'hidden');
}).on("hidden", function () {
        $("body").css('overflow', 'auto');
});

but all content jump when open model.

if you using niceScroller then ... it will work....

var bModal = $('#basicModal'); var bModalBody = bModal.find('.modal-body'); bModal.on('shown.bs.modal', function(e){ bModalBody.niceScroll({ touchbehavior: true, autohidemode:false }); }).on('hide.bs.modal', function(e){ bModalBody.niceScroll().remove(); });

Was this page helpful?
0 / 5 - 0 ratings