您好,登錄后才能下訂單哦!
bootstrap中有javascript插件modal也就是對話框,加入拖拽功能,具體內(nèi)容如下
在使用modal時首選需要引用js
<link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet"> <script src="http://cdn.bootcss.com/jquery/2.1.4/jquery.js"></script> <script src="http://cdn.bootcss.com/jqueryui/1.11.4/jquery-ui.js"></script> // 完成拖拽功能 <script src="http://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 rel="external nofollow" rel="external nofollow" rel="stylesheet"> <script src="http://cdn.bootcss.com/jquery/2.1.4/jquery.js"></script> <script src="http://cdn.bootcss.com/jqueryui/1.11.4/jquery-ui.js"></script> <script src="http://cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.js"></script> </head> <body> <button class="btn btn-default">顯示Modal</button> <div class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> <h5 class="modal-title">Modal title</h5> </div> <div class="modal-body"> <p>One fine body…</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">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插件使用詳細請看:鏈接地址
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。