Draggable JS Bootstrap modal - performance issues

后端 未结 6 1257
感情败类
感情败类 2021-02-02 02:59

For a project at work we use Bootstrap Modal windows in JavaScript. We would like to make some of the windows movable, but we are running into performance issues with JQuery.

6条回答
  •  情书的邮戳
    2021-02-02 03:21

    With Bootstrap 3.3 and jQuery UI 1.1 I'm adding a class called "modal-draggable" to the element with the "modal" class.

    It binds to the .modal-dialog element inside containers with the .modal-draggable class (unlike some examples here which bind to the actual container).

    There is some CSS so scrolling for long dialogs still work across devices of all screen sizes.

    CSS:

    .modal-draggable .modal-backdrop {
      position: fixed;
    }
    
    .modal.modal-draggable {
        overflow: overflow-y;
    }
    
    .modal-draggable .modal-header:hover {
      cursor: move;
    }
    

    JavaScript:

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

    See the JS Fiddle here for a demo: http://jsfiddle.net/jcosnn6u/3/

    NB: So far I have only tested this in Chrome, Firefox and Safari and mobile devices, so can't comment on Internet Explorer compatibility.

提交回复
热议问题