插件描述:iziModal是一款時尚炫酷的jQuery模態窗口插件。該模態窗口插件提供基本的打開模態窗口動畫特效,并且可以調用iframe內容,Ajax加載,制作alert效果,加載超大內容等。
在頁面中引入iziModal.min.css和jquery、iziModal.min.js文件。
<link rel="stylesheet" href="iziModal.min.css"> <script src="jquery.min.js" type="text/javascript"></script> <script src="iziModal.min.js" type="text/javascript"></script>
可以通過按鈕或<a>元素來觸發一個模態窗口。
<!-- Trigger to open Modal --> <a href="#" class="trigger">打開模態窗口</a> <!-- 模態窗口 --> <div id="modal"> <!-- 模態窗口的內容 --> </div>
在頁面DOM元素加載完畢之后,可以通過iziModal()方法來初始化該模態窗口插件。
$("#modal").iziModal();
或者也可以通過jqurey事件來打開模態窗口。
$(document).on('click', '.trigger', function (event) { event.preventDefault(); $('#modal').iziModal('open', this); // 需要帶上 "this" });
要在模態窗口中使用iframe功能,結構如下:
<a href="http://www.jq22.com" class="trigger">打開模態窗口</a>
初始化:
$("#modal").iziModal({ iframe: true, iframeHeight: 800, iframeURL: "http://www.jq22.com" });
或者也可以通過jquery事件來打開模態窗口。
$(document).on('click', '.trigger', function (event) { event.preventDefault(); $('#modal').iziModal('open', this); // 需要帶上 "this" });
iziModal模態窗口插件配置有Ajax功能。
$("#modal").iziModal('open', function(modal){ modal.startLoading(); $.get('/path/to/file', function(data) { $("#modal .iziModal-content").html(data); modal.stopLoading(); }); });
iziModal模態窗口插件的默認配置參數如下:
$("#modal").iziModal({ title: "", subtitle: "", theme: "", headerColor: "#88A0B9", overlayColor: "rgba(0, 0, 0, 0.4)", iconColor: "", iconClass: null, width: 600, padding: 0, iframe: false, iframeHeight: 400, iframeURL: null, overlayClose: true, closeOnEscape: true, bodyOverflow: false, focusInput: true, autoOpen: false, transitionInModal: 'transitionIn', transitionOutModal: 'transitionOut', transitionInOverlay: 'fadeIn', transitionOutOverlay: 'fadeOut', onOpening: function() {}, onOpened: function() {}, onClosing: function() {}, onClosed: function() {} });
參數 | 默認值 | 描述 |
title | "" | 模態窗口的標題。 |
subtitle | "" | 模態窗口的子標題。 |
theme | "" | 模態窗口的主題,可以是空或"light"。 |
headerColor | #6d7d8d | 模態窗口的頭部顏色。 |
overlayColor | rgba(0,0,0,0.4) | 遮罩層的顏色。 |
iconColor | "" | 頭部圖標的顏色。 |
iconClass | null | 圖標圖標的class(你使用的字體圖標的class名稱) |
width | 600 | 模態窗口的固定寬度。你可以使用%, px, em 或 cm。如果不帶單位,默認為像素。 |
padding | 0 | 模態窗口的內邊距。 |
iframe | false | 是否在模態窗口中啟用iframe功能。 |
iframeHeight | null | iframe的高度。 |
iframeURL | null | iframe加載內容的URL地址。如果沒有設置,可以使用超鏈接的地址來作為URL地址。 |
overlayClose | true | 是否允許點擊模態窗口的外部來關閉模態窗口。 |
closeOnEscape | true | 是否允許通過點擊ESC鍵來關閉模態窗口。 |
bodyOverflow | false | 強制在打開模態窗口時超出文檔的內容被隱藏。 |
focusInput | true | 設置為true時,當打開模態窗口時,第一個可見的表單域將被激活。 |
autoOpen | false | 是否自動打開模態窗口。 |
transitionInModal | transitionIn | 打開模態窗口的默認過渡動畫。 |
transitionOutModal | transitionOut | 關閉模態窗口的默認過渡動畫。 |
transitionInOverlay | fadeIn | 遮罩層打開時的過渡動畫。 |
transitionOutOverlay | fadeOut | 遮罩層關閉時的過渡動畫。 |
onOpening | function() {} | 模態窗口打開時的回調函數。 |
onOpened | function() {} | 模態窗口打開后的回調函數。 |
onClosing | function() {} | 模態窗口關閉時的回調函數。 |
onClosed | function() {} | 模態窗口關閉后的回調函數。 |
$('#modal').iziModal();//初始化模態窗口。
$('#modal').iziModal('open');//打開模態窗口。
$('#modal').iziModal('close');//關閉模態窗口。
$('#modal').iziModal('getState');//獲取模態窗口的狀態,返回:{'closed'|'closing'|'opened'|'opening'}。
$('#modal').iziModal('startLoading');//開啟模態窗口中的加載進度指示器。
$('#modal').iziModal('stopLoading');//關閉模態窗口中的加載進度指示器。
$('#modal').iziModal('destroy');//銷毀模態窗口。
$('#modal').iziModal('setHeaderColor', 'color');//設置模態窗口頭部的背景顏色。
$('#modal').iziModal('setTitle', 'Title');//設置模態窗口的標題。
$('#modal').iziModal('setSubtitle', 'Subtitle');//設置模態窗口的子標題。
$('#modal').iziModal('setIconClass', 'iconClass');//設置模態窗口的圖標。
$('#modal').iziModal('recalculateLayout');//重新計算模態窗口的尺寸和位置。
Opening:在模態窗口打開時觸發。
$(document).on('opening', '#modal', function (e) { //console.log('Modal is opening'); });
Opened:在模態窗口打開之后觸發。
$(document).on('opened', '#modal', function (e) { //console.log('Modal is opened'); });
Closing:在模態窗口關閉時觸發。
$(document).on('closing', '#modal', function (e) { //console.log('Modal is closing'); });
Closed:在模態窗口關閉之后觸發。
$(document).on('closed', '#modal', function (e) { // console.log('Modal is closed'); });