1.设置style:
1 <style> 2 .modal-header { 3 cursor: move; 4 } 5 </style>
2.添加下列代码:
1 <script> 2 $(".modal-header").on("mousedown", function(mousedownEvt) { 3 var $draggable = $(this); 4 var x = mousedownEvt.pageX - $draggable.offset().left, 5 y = mousedownEvt.pageY - $draggable.offset().top; 6 $("body").on("mousemove.draggable", function(mousemoveEvt) { 7 $draggable.closest(".modal-dialog").offset({ 8 "left": mousemoveEvt.pageX - x, 9 "top": mousemoveEvt.pageY - y 10 }); 11 }); 12 $("body").one("mouseup", function() { 13 $("body").off("mousemove.draggable"); 14 }); 15 $draggable.closest(".modal").one("bs.modal.hide", function() { 16 $("body").off("mousemove.draggable"); 17 }); 18 }); 19 </script>
3.对于第一步,也可通过script来设置:
1 $(".modal-header").css("cursor", "move");