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