Make bootstrap modal draggable and keep background usable

arie :

I'm trying to make a bootstrap modal draggable anywhere on the page and when the modal is open, I want the user to be able to continue using the page.

I was able to make the modal draggable with jquery-ui but I'm stuck on making the page usable while the modal is open. Tried several suggestions with CSS but none work quite as I'd like them to.

This makes the page usable but the modal is limited to only a part of the page: Bootstrap Modal - make background clickable without closing out modal

Same as this one: Enable background when open bootstrap modal popup

Is it possible to achieve this with bootstrap modal at all?

This is my JS:

$('#btn1').click(function() {
    var modalDiv = $('#myModal');
    modalDiv.modal({backdrop: false, show: true});

    $('.modal-dialog').draggable({
      handle: ".modal-header"
    });
});

JSFiddle link: https://jsfiddle.net/ntLpg6hw/1/

Dan Kreiger :

This is really cool!

I think all you need is a little css.

#myModal {
  position: relative;
}

.modal-dialog {
  position: fixed;
  width: 100%;
  margin: 0;
  padding: 10px;
}

You should also add some jQuery to reset your modal position on button click.

$('#btn1').click(function() {
  // reset modal if it isn't visible
  if (!($('.modal.in').length)) {
    $('.modal-dialog').css({
      top: 0,
      left: 0
    });
  }
  $('#myModal').modal({
    backdrop: false,
    show: true
  });

  $('.modal-dialog').draggable({
    handle: ".modal-header"
  });
});

Check out the Fiddle


Note: Facebook is now doing something similar with external newsfeed videos. If you scroll away from a video while watching it, it becomes a drag and drop video.

Basically, their video popup parent container is position: relative, and the direct child of that container is position: fixed. The same strategy is used here.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

My Bootstrap modal is not draggable?

how to make bootstrap modal draggable and scrollable on android device

Make jQuery UI Draggable Cursor centered in Bootstrap Modal when dragging

Bootstrap 3 modal: make it movable/draggable without jquery-ui

Bootstrap Modal - make background clickable without closing out modal

How to make bootstrap dropdown draggable?

Bootstrap modal enable background

bootstrap modal background black

Background image in bootstrap modal

Jquery draggable with bootstrap modal, scroller strange behaviour

Modal under background fade bootstrap

Bootstrap modal appearing under background

Bootstrap 3 modal background is missing

BootStrap Modal background scroll on iOS

background pixels flickering on bootstrap modal

Bootstrap modal displays grey background

How to make a draggable background image with background-position and percentage values?

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

How can i apply a draggable directive to bootstrap modal using angularJS?

How to make the modal dialogue box draggable when rendered with renderUI()?

Trying to make bootstrap modal wider

how to make a transparent modal in bootstrap?

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

How to make Google map draggable and keep marker in the center of the screen on Flutter?

How to generate a Twitter Bootstrap modal but keep it hidden

Bootstrap modal: background jumps to top on toggle

Enable background use with modal open in Bootstrap 4

How to change background color of react bootstrap modal

Bootstrap 4 Modal Background not responsive on mobile