Ply是一款非常实用的跨浏览器模态窗口|对话框|提示框插件。可以用它来制作各种提示框,警告框,对话框,模态窗口等。它使用ES6语法编写,可以兼容IE8以上的浏览器。它的特点还有:
在页面中引入ply.css和Ply.js文件。
<link href="./ply.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="js/Ply.js"></script>
然后使用下面的方法来创建一个对话框。
Ply.dialog("alert", "Wow!").always(function (ui) { ui.state; // true — "OK", false — "cancel" ui.by; // submit, overlay, esc, "x" ui.widget; // Ply instance }); //or Ply.dialog("confirm", "Do you like it?") .done(function (ui) { // OK }) .fail(function (ui) { // Cancel }) .always(function (ui) { if (ui.state) { // Clicked "OK" } else { // Clicked "Cancel" // details: `ui.by` — "cancel", "overlay", "esc", "x" } });
要创建一个多步骤的对话框,可以使用下面的方法。
Ply.dialog({ "init-state": { ui: "alert", data: "Wow!", next: "other-step" nextEffect: "3d-flip[180,-180]" }, "other-step": { ui: "confirm", data: { text: "What's next?", ok: "Exit", // button text cancel: "Back" }, back: "init-state", backEffect: "3d-flip[-180,180]" } }).always(function (ui) { if (ui.state) { // OK } else { // Cancel // ui.by — 'overlay', 'x', 'esc' } })
new Ply(el[, options])
el:String|HTMLElement
:内容层Object
-层的选项new Ply(options)
Object
-层的选项var ply = new Ply({ el: "...", // HTML-content effect: "fade", // or ["open-effect:duration", "close-effect:duration"] layer: {}, // default css overlay: { // defaults css opacity: 0.6, backgroundColor: "#000" }, flags: { // defaults closeBtn: true, // presence close button "?" bodyScroll: false, // disable scrollbar at body closeByEsc: true, // close by press on `Esc` key closeByOverlay: true, // close by click on the overlay hideLayerInStack: true, // hide the layer if it is not the first in the stack visibleOverlayInStack: false // visibility overlay, if the layer is not the first in the stack }, // Callback oninit: function (ply) {}, onopen: function (ply) {}, onclose: function (ply) {}, ondestory: function (ply) {}, onaction: function (ui) {}, }); // And ply.open().always(function () { ply.swap({ el: ".." }, "3d-flip").always(function () { ply.close(); }); });
Promise
Promise
Promise
:从一个层切换到另一个层Promise
:从一个层的内容切换到另一个层的内容Ply.dialog("alert", { effect: ["fade", "scale"] }, "Fade & scale");
Ply.effects["my-effect"] = { open: { layer: "fade-in", overlay: "background-in" }, close: { layer: "fade-out", overlay: "background-out" } }; Ply.effects["background-in"] = { "from": { opacity: 0, backgroundColor: "red" }, "to": { opacity: 1, backgroundColor: "white" } }; Ply.effects["background-out"] = { "from": { opacity: 1, backgroundColor: "white" }, "to": { opacity: 0, backgroundColor: "green" } };
Ply|null
Number
String|Boolean
String|Boolean
String|Boolean
String|Boolean
String|Boolean
String|Boolean
String
— "OK"String
— "Cancel"String
— "?"Object
— cssObject
— 遮罩样式
rgb(0, 0, 0)
Object
false
Esc
键关闭层,默认值true
true
build(tag:String|Object):HTMLElement
Ply.build(); // <div/> Ply.build("input"); // <input/> Ply.build(".foo"); // <div class="foo"/> Ply.build(".foo.bar"); // <div class="foo bar"/> Ply.build({ // <input type="password" class="foo" style="padding: 10px" maxlength="32"/> tag: "input.foo", type: "password", css: { padding: "10px" }, maxlength: 32 }); Ply.build({ text: "<i>?</i>" }); // <div><i>?</i></div> Ply.build({ html: "<i>!</i>" }); // <div><i>!</i></div>
append(parent:HTMLElement, el:HTMLElement)
remove(el:HTMLElement)
addEvent(el:HTMLElement, name:String, fn:Function)
removeEvent(el:HTMLElement, name:String, fn:Function)