Bootstrap 4 how to make modal that doesn't block or affect background and scrolling

nikib3ro

I'm trying to create Bootstrap modal that will be shown while still allowing user to interact with rest of the website. The steps I've done so far are:

  1. Added data-backdrop="false" to modal div to hide shadow of backdrop
  2. Added keyboard: false to prevent closing of modal by keyboard ESC
  3. Custom CSS class to make dialog show in bottom right corner:

    .modalDialog {
        position: fixed;
        bottom: 20px;
        right: 20px;
        margin: 0px;
    }
    

This changes make model appear non-blocking... but there is still problem with page not being scrollable and elements not being clickable. I've tried most of the answers here on StackOverflow but all of them are outdated (for version of Bootstrap before 4).

So, is there a way to do this in Bootstrap 4 that is framework supported, or you are forced to go with custom CSS classes?

nikib3ro

I've resolved this by removing reliance on Bootstrap for opening modal and went with custom CSS. If we look at Bootstrap Modal example as starting point you would need to do:

  1. Remove root container div... in example that's <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> and then matching </div>
  2. Add id="modalDialog" to body, resulting in <div id="modalDialog" class="modal-dialog">
  3. Target that with custom CSS I've left previously:

    .modalDialog {
        position: fixed;
        bottom: 20px;
        right: 20px;
        margin: 0px;
    }
    
  4. Use something like Animate.Css to provide intro for modal open. To emulate what Bootstrap does you can use fadeInDown, resulting in: <div id="modalDialog" class="modal-dialog animated fadeInDown">

  5. If you want close animation just create custom JavaScript function that you invoke with button click. Example close function: $("#modalDialog").addClass('animated fadeOutDown');

Of course you now won't need Bootstrap modal() call. Hope it solves you the problem... I'll see if I can create JsFiddle for better demo.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Bootstrap 4 modal window doesn't open

Modal Bootstrap 4 doesn't show

Bootstrap modal not becoming active element on toggle, background scrolling but modal not scrolling

Bootstrap's Modal box - background doesn't fade out on show

Scrolling a dropdown in a modal in Bootstrap4

Bootstrap 4 modal fades screen but doesn't show

How to prevent background scrolling when Bootstrap 3 modal open on mobile browsers?

Bootstrap Modal doesn't appear

Modal doesn't show bootstrap

Bootstrap Modal doesn't popup

Make bootstrap modal draggable and keep background usable

background scrolling bar when stacking bootstrap modal windwos

Enable background use with modal open in Bootstrap 4

Bootstrap 4 Modal Background not responsive on mobile

Bootstrap Modal - make background clickable without closing out modal

how to make a transparent modal in bootstrap?

My bootstrap modal shows up fine, however the background doesn't fade

RoR - pass param to Bootstrap modal. Background doesn't fade out

Bootstrap modal background won't disappear

How to execute a method every second on a background thread so it doesn't affect the performance of the app

How to ignore SwiftUI modal background, or make modal background clear/transparent?

Bootstrap modal not scrolling horizontally

Modal dialog doesn't darken the background on android

Background of my modal doesn't change

How do you make a scrolling background in pygame?

How to use bootstrap 4 modals as "block ui" - modal screen that blocks input and show "wait a minute.." label?

How to change background color of react bootstrap modal

how to create bootstrap modal with transparent background

Bootstrap modal event doesn't trigger