BootStrap modal实现拖拽功能

bootstrap中有javascript插件modal也就是对话框,加入拖拽功能,具体内容如下

在使用modal时首选需要引用js

<link href="https://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.css"> <script src="https://cdn.bootcss.com/jquery/2.1.4/jquery.js"></script> <script src="https://cdn.bootcss.com/jqueryui/1.11.4/jquery-ui.js"></script> // 完成拖拽功能 <script src="https://cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.js"></script> // 完成Modal

编辑Html代码

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>BootStrap Modal</title> <link href="https://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.css"> <script src="https://cdn.bootcss.com/jquery/2.1.4/jquery.js"></script> <script src="https://cdn.bootcss.com/jqueryui/1.11.4/jquery-ui.js"></script> <script src="https://cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.js"></script> </head> <body> <button>显示Modal</button> <div> <div> <div> <div> <button type="button" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span> </button> <h4>Modal title</h4> </div> <div> <p>One fine body&hellip;</p> </div> <div> <button type="button" data-dismiss="modal">Close</button> <button type="button">Save changes</button> </div> </div> <!-- /.modal-content --> </div> <!-- /.modal-dialog --> </div> <!-- /.modal --> <script type="text/javascript"> var $button = $('.btn-default'), $modal = $('#myModal'); $(function(){ $button.on('click',function(event) { event.preventDefault(); /* Act on the event */ $modal.show( '500', function() { var modal = $(this); modal.find('.modal-title').text('New message to '); $.ajax({}); }); $modal.modal('show'); }); }); </script> </body> </html>

要完成拖拽功能需要修改一下javascript

<script type="text/javascript"> var $button = $('.btn-default'), $modal = $('#myModal'); $(function(){ $button.on('click',function(event) { event.preventDefault(); /* Act on the event */ $modal.show( '500', function() { var modal = $(this); modal.find('.modal-title').text('New message to '); $.ajax({}); }); /* 完成拖拽 */ $modal.draggable({ cursor: "move", handle: '.modal-header' }); $modal.modal('show'); }); }); </script>

推荐

有关bootstrap modal插件使用详细请看:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/9152df421b79205a725f6f72171bd675.html