jQuery UI モーダル(modal)でダイアログを開くサンプルコードです。
※ jQuery 3.1 / jQuery UI 1.12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | // サンプルコード <button id="open_modal">click!</button> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css"> <script> $(function(){ $('#open_modal').on('click', function() { // 多重起動防止 if ($('div#dialog_window').length) { $('div#dialog_window').remove(); } // 表示URL ex) /users var get_url = '表示URL'; // モーダル画面 幅・高さ(99%) var w = Math.round($(window).width() * 0.99); var h = Math.round($(window).height() * 0.99); $('body').append('<div id="dialog_window"></div>'); $('div#dialog_window').dialog({ autoOpen: false, width: w, height: h, modal: true, resizable: false, position: { my: 'center', at: 'center', of: window }, close: function() { $('div#dialog_window').remove(); }, open: function() { $.ajaxSetup({cache: false}); // キャッシュ対策 $('.ui-dialog').addClass('hideWrap'); // load完了後まで非表示 $('.ui-dialog-titlebar').removeClass('ui-widget-header'); // .ui-widget-header削除 $('.ui-widget-overlay').css('position', 'fixed'); $('div#dialog_window').load(get_url, function(text, status) { if (status == 'success') { $('.ui-dialog').removeClass('hideWrap'); // load完了後に表示 } else if (status == 'error') { $('div#dialog_window').dialog('close'); } }); } }); // open $('div#dialog_window').dialog('open'); // モーダル背景をクリックしたら閉じる $(document).on('click', '.ui-widget-overlay', function() { $(this).prev().find('.ui-dialog-content').dialog('close'); }); }); }); </script> |