以下是 jQuery模态对话框插件zebra_dialog js代码 的示例演示效果:
部分效果截图1:
部分效果截图2:
部分效果截图3:
HTML代码(index.html):
<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery模态对话框插件zebra_dialog</title>
<link rel="stylesheet" href="css/reset.css" type="text/css">
<link rel="stylesheet" href="css/default/zebra_dialog.css" type="text/css">
<link rel="stylesheet" href="css/style.css" type="text/css">
<link rel="stylesheet" type="text/css" href="css/default.css">
<link rel="stylesheet" href="libraries/highlight/public/css/ir_black.css" type="text/css">
</head>
<body>
<header class="htmleaf-header">
<div class="htmleaf-demo center">
<a href="index.html" class="current">默认对话框</a>
<a href="index2.html">扁平风格</a>
</div>
</header>
<section class="htmleaf-container">
<div class="main-wrapper">
<h3>Zebra_Dialog Demo:默认对话框</h3>
<strong>1.</strong> 默认不带参数配置的对话框。点击<a href="javascript:void(0)" id="example1">这里</a> 查看效果。
<pre><code class="javascript">$.Zebra_Dialog('<strong>Zebra_Dialog</strong>, a small, compact and highly configurable dialog box plugin for jQuery');</code></pre>
<p> </p>
<strong>2.</strong> 以下是5种类型的对话框: <a href="javascript:void(0)" id="example2_1">error</a>, <a href="javascript:void(0)" id="example2_2">warning</a>, <a href="javascript:void(0)" id="example2_3">question</a>, <a href="javascript:void(0)" id="example2_4">information</a> and <a href="javascript:void(0)" id="example2_5">confirmation</a>.
<pre><code class="javascript">// this example is for the "error" box only
// for the other types the "type" property changes to "warning", "question", "information" and "confirmation"
// and the text for the "title" property also changes
$.Zebra_Dialog('<strong>Zebra_Dialog</strong>, a small, compact and highly configurable dialog box plugin for jQuery', {
'type': 'error',
'title': 'Error'
});</code></pre>
<p> </p>
<strong>3.</strong> 自定义按钮和回调函数。点击<a href="javascript:void(0)" id="example3">这里</a>查看效果。<br><br>
<em>注意:onClose事件在对话框关闭后才被执行。你可以参考下一个例子如何在关闭对话框之前来执行函数。</em>
<pre><code class="javascript">$.Zebra_Dialog('<strong>Zebra_Dialog</strong>, a small, compact and highly configurable dialog box plugin for jQuery', {
'type': 'question',
'title': 'Custom buttons',
'buttons': ['Yes', 'No', 'Help'],
'onClose': function(caption) {
alert((caption != '' ? '"' + caption + '"' : 'nothing') + ' was clicked');
}
});</code></pre>
<p> </p>
<strong>3.1</strong>自定义带回调函数的按钮。点击 <a href="javascript:void(0)" id="example31">这里</a>查看效果。<br><br>
<em>注意:附加到按钮上的函数会在对话框关闭前触发(按钮一点就就触发)。</em>
<pre><code class="javascript">$.Zebra_Dialog('<strong>Zebra_Dialog</strong>, a small, compact and highly configurable dialog box plugin for jQuery', {
'type': 'question',
'title': 'Custom buttons',
'buttons': [
{caption: 'Yes', callback: function() { alert('"Yes" was clicked')}},
{caption: 'No', callback: function() { alert('"No" was clicked')}},
{caption: 'Cancel', callback: function() { alert('"Cancel" was clicked')}}
]
});</code></pre>
<p> </p>
<strong>4.</strong> 将对话框放置在屏幕的右上角位置。点击<a href="javascript:void(0)" id="example4">这里</a>查看效果。
<pre><code class="javascript">$.Zebra_Dialog('<strong>Zebra_Dialog</strong>, a small, compact and highly configurable dialog box plugin for jQuery', {
'title': 'Custom positioning',
'position': ['right - 20', 'top + 20']
});</code></pre>
<p> </p>
<strong>5.</strong> 使用消息提示模式-不带按钮,2秒后自动消失。
<br><br>
<em>注意:这种模式需要使用new关键字来实例化对象,最后打开的对话框将被关闭。</em><br>
点击<a href="javascript:void(0)" id="example5">这里</a>查看效果。
<pre><code class="javascript">new $.Zebra_Dialog('<strong>Zebra_Dialog</strong>, a small, compact and highly configurable dialog box plugin for jQuery', {
'buttons': false,
'modal': false,
'position': ['right - 20', 'top + 20'],
'auto_close': 2000
});</code></pre>
<p> </p>
<strong>6.</strong> 通过AJAX加载外部内容。
点击<a href="javascript:void(0)" id="example6">这里</a>查看效果。
<pre><code class="javascript">new $.Zebra_Dialog('<strong>Some dummy content:</strong><br><br>', {
'source': {'ajax': 'ajax.html'},
width: 600,
'title': 'External content loaded via AJAX'
});</code></pre>
<p> </p>
<strong>6.1</strong> 在iFrame中加载外部内容。
点击 <a href="javascript:void(0)" id="example61">这里</a> 查看效果。
<pre><code class="javascript">new $.Zebra_Dialog('<strong>Content loaded via AJAX:</strong>', {
source: {'iframe': {
'src': 'http://en.m.wikipedia.org/wiki/Dialog_box',
'height': 500
}},
width: 800,
title: 'External content loaded in an iFrame'
});</code></pre>
<p> </p>
<strong>7.</strong> 自定义外观-标题为蓝黑色背景,以及一个自定义图标。
<br><br>CSS样式为:
<pre><code class="css">/* Notice how we're targting the dialog box's title bar through the custom class */
.myclass .ZebraDialog_Title { background: #DEDEDE; border-bottom: 1px solid #222 }
.myclass .ZebraDialog_Body { background-image: url('coffee_48.png') }</code></pre>
点击 <a href="javascript:void(0)" id="example7">这里</a> 查看效果。<br>
<pre><code class="javascript">new $.Zebra_Dialog('Buy me a coffee if you like this plugin!', {
'custom_class': 'myclass',
'title': 'Customizing the appearance'
});</code></pre>
<p> </p>
</div>
<div id="boxcontent" style="display: none">
<p>Lorem ipsum dolor sit amet consectetuer lorem tristique nec et euismod. At Donec nunc Morbi Sed Curabitur lobortis
leo porttitor Aenean nibh. Sed Curabitur dignissim nibh ac pretium tempus interdum Curabitur Vestibulum Morbi. Lacinia
in ante porta quis Vestibulum Nullam enim laoreet enim accumsan. Et non Proin semper rutrum sapien lorem in sit et
auctor. Quis sem pellentesque quis dui ligula vitae leo velit semper euismod.</p>
<p>Lorem ipsum dolor sit amet consectetuer lorem tristique nec et euismod. At Donec nunc Morbi Sed Curabitur lobortis
leo porttitor Aenean nibh. Sed Curabitur dignissim nibh ac pretium tempus interdum Curabitur Vestibulum Morbi. Lacinia
in ante porta quis Vestibulum Nullam enim laoreet enim accumsan. Et non Proin semper rutrum sapien lorem in sit et
auctor. Quis sem pellentesque quis dui ligula vitae leo velit semper euismod.</p>
<p>Lorem ipsum dolor sit amet consectetuer lorem tristique nec et euismod. At Donec nunc Morbi Sed Curabitur lobortis
leo porttitor Aenean nibh. Sed Curabitur dignissim nibh ac pretium tempus interdum Curabitur Vestibulum Morbi. Lacinia
in ante porta quis Vestibulum Nullam enim laoreet enim accumsan. Et non Proin semper rutrum sapien lorem in sit et
auctor. Quis sem pellentesque quis dui ligula vitae leo velit semper euismod.</p>
</div>
</section>
<script src="js/jquery-1.11.0.min.js" type="text/javascript"></script>
<script type="text/javascript" src="libraries/highlight/public/javascript/highlight.js"></script>
<script type="text/javascript" src="js/zebra_dialog.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<script type="text/javascript">
hljs.initHighlightingOnLoad();
</script>
</body>
</html>
HTML代码(index2.html):
<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery模态对话框插件zebra_dialog</title>
<link rel="stylesheet" href="css/reset.css" type="text/css">
<link rel="stylesheet" href="css/flat/zebra_dialog.css" type="text/css">
<link rel="stylesheet" href="css/style.css" type="text/css">
<link rel="stylesheet" type="text/css" href="css/default.css">
<link rel="stylesheet" href="libraries/highlight/public/css/ir_black.css" type="text/css">
<!--[if IE]>
<script src="http://libs.useso.com/js/html5shiv/3.7/html5shiv.min.js"></script>
<![endif]-->
</head>
<body>
<header class="htmleaf-header">
<div class="htmleaf-demo center">
<a href="index.html">默认对话框</a>
<a href="index2.html" class="current">扁平风格</a>
</div>
</header>
<section class="htmleaf-container">
<div class="main-wrapper">
<h3>Zebra_Dialog Demo:扁平风格</h3>
<strong>1.</strong> 默认不带参数配置的对话框。点击<a href="javascript:void(0)" id="example1">这里</a> 查看效果。
<pre><code class="javascript">$.Zebra_Dialog('<strong>Zebra_Dialog</strong>, a small, compact and highly configurable dialog box plugin for jQuery');</code></pre>
<p> </p>
<strong>2.</strong> 以下是5种类型的对话框: <a href="javascript:void(0)" id="example2_1">error</a>, <a href="javascript:void(0)" id="example2_2">warning</a>, <a href="javascript:void(0)" id="example2_3">question</a>, <a href="javascript:void(0)" id="example2_4">information</a> and <a href="javascript:void(0)" id="example2_5">confirmation</a>.
<pre><code class="javascript">// this example is for the "error" box only
// for the other types the "type" property changes to "warning", "question", "information" and "confirmation"
// and the text for the "title" property also changes
$.Zebra_Dialog('<strong>Zebra_Dialog</strong>, a small, compact and highly configurable dialog box plugin for jQuery', {
'type': 'error',
'title': 'Error'
});</code></pre>
<p> </p>
<strong>3.</strong> 自定义按钮和回调函数。点击<a href="javascript:void(0)" id="example3">这里</a>查看效果。<br><br>
<em>注意:onClose事件在对话框关闭后才被执行。你可以参考下一个例子如何在关闭对话框之前来执行函数。</em>
<pre><code class="javascript">$.Zebra_Dialog('<strong>Zebra_Dialog</strong>, a small, compact and highly configurable dialog box plugin for jQuery', {
'type': 'question',
'title': 'Custom buttons',
'buttons': ['Yes', 'No', 'Help'],
'onClose': function(caption) {
alert((caption != '' ? '"' + caption + '"' : 'nothing') + ' was clicked');
}
});</code></pre>
<p> </p>
<strong>3.1</strong>自定义带回调函数的按钮。点击 <a href="javascript:void(0)" id="example31">这里</a>查看效果。<br><br>
<em>注意:附加到按钮上的函数会在对话框关闭前触发(按钮一点就就触发)。</em>
<pre><code class="javascript">$.Zebra_Dialog('<strong>Zebra_Dialog</strong>, a small, compact and highly configurable dialog box plugin for jQuery', {
'type': 'question',
'title': 'Custom buttons',
'buttons': [
{caption: 'Yes', callback: function() { alert('"Yes" was clicked')}},
{caption: 'No', callback: function() { alert('"No" was clicked')}},
{caption: 'Cancel', callback: function() { alert('"Cancel" was clicked')}}
]
});</code></pre>
<p> </p>
<strong>4.</strong> 将对话框放置在屏幕的右上角位置。点击<a href="javascript:void(0)" id="example4">这里</a>查看效果。
<pre><code class="javascript">$.Zebra_Dialog('<strong>Zebra_Dialog</strong>, a small, compact and highly configurable dialog box plugin for jQuery', {
'title': 'Custom positioning',
'position': ['right - 20', 'top + 20']
});</code></pre>
<p> </p>
<strong>5.</strong> 使用消息提示模式-不带按钮,2秒后自动消失。
<br><br>
<em>注意:这种模式需要使用new关键字来实例化对象,最后打开的对话框将被关闭。</em><br>
点击<a href="javascript:void(0)" id="example5">这里</a>查看效果。
<pre><code class="javascript">new $.Zebra_Dialog('<strong>Zebra_Dialog</strong>, a small, compact and highly configurable dialog box plugin for jQuery', {
'buttons': false,
'modal': false,
'position': ['right - 20', 'top + 20'],
'auto_close': 2000
});</code></pre>
<p> </p>
<strong>6.</strong> 通过AJAX加载外部内容。
点击<a href="javascript:void(0)" id="example6">这里</a>查看效果。
<pre><code class="javascript">new $.Zebra_Dialog('<strong>Some dummy content:</strong><br><br>', {
'source': {'ajax': 'ajax.html'},
width: 600,
'title': 'External content loaded via AJAX'
});</code></pre>
<p> </p>
<strong>6.1</strong> 在iFrame中加载外部内容。
点击 <a href="javascript:void(0)" id="example61">这里</a> 查看效果。
<pre><code class="javascript">new $.Zebra_Dialog('<strong>Content loaded via AJAX:</strong>', {
source: {'iframe': {
'src': 'http://en.m.wikipedia.org/wiki/Dialog_box',
'height': 500
}},
width: 800,
title: 'External content loaded in an iFrame'
});</code></pre>
<p> </p>
<strong>7.</strong> 自定义外观-标题为蓝黑色背景,以及一个自定义图标。
<br><br>CSS样式为:
<pre><code class="css">/* Notice how we're targting the dialog box's title bar through the custom class */
.myclass .ZebraDialog_Title { background: #DEDEDE; border-bottom: 1px solid #222 }
.myclass .ZebraDialog_Body { background-image: url('coffee_48.png') }</code></pre>
点击 <a href="javascript:void(0)" id="example7">这里</a> 查看效果。<br>
<pre><code class="javascript">new $.Zebra_Dialog('Buy me a coffee if you like this plugin!', {
'custom_class': 'myclass',
'title': 'Customizing the appearance'
});</code></pre>
<p> </p>
</div>
<div id="boxcontent" style="display: none">
<p>Lorem ipsum dolor sit amet consectetuer lorem tristique nec et euismod. At Donec nunc Morbi Sed Curabitur lobortis
leo porttitor Aenean nibh. Sed Curabitur dignissim nibh ac pretium tempus interdum Curabitur Vestibulum Morbi. Lacinia
in ante porta quis Vestibulum Nullam enim laoreet enim accumsan. Et non Proin semper rutrum sapien lorem in sit et
auctor. Quis sem pellentesque quis dui ligula vitae leo velit semper euismod.</p>
<p>Lorem ipsum dolor sit amet consectetuer lorem tristique nec et euismod. At Donec nunc Morbi Sed Curabitur lobortis
leo porttitor Aenean nibh. Sed Curabitur dignissim nibh ac pretium tempus interdum Curabitur Vestibulum Morbi. Lacinia
in ante porta quis Vestibulum Nullam enim laoreet enim accumsan. Et non Proin semper rutrum sapien lorem in sit et
auctor. Quis sem pellentesque quis dui ligula vitae leo velit semper euismod.</p>
<p>Lorem ipsum dolor sit amet consectetuer lorem tristique nec et euismod. At Donec nunc Morbi Sed Curabitur lobortis
leo porttitor Aenean nibh. Sed Curabitur dignissim nibh ac pretium tempus interdum Curabitur Vestibulum Morbi. Lacinia
in ante porta quis Vestibulum Nullam enim laoreet enim accumsan. Et non Proin semper rutrum sapien lorem in sit et
auctor. Quis sem pellentesque quis dui ligula vitae leo velit semper euismod.</p>
</div>
</section>
<script src="js/jquery-1.11.0.min.js" type="text/javascript"></script>
<script type="text/javascript" src="libraries/highlight/public/javascript/highlight.js"></script>
<script type="text/javascript" src="js/zebra_dialog.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<script type="text/javascript">
hljs.initHighlightingOnLoad();
</script>
</body>
</html>
JS代码(main.js):
$(document).ready(function(){
$('#example1').bind('click',function(e){
e.preventDefault();
$.Zebra_Dialog('<strong>Zebra_Dialog</strong>,a small,compact and highly configurable dialog box plugin for jQuery');
}
);
$('#example2_1').bind('click',function(e){
e.preventDefault();
$.Zebra_Dialog('<strong>Zebra_Dialog</strong> has no dependencies other than <em>jQuery 1.5.2+</em> and works in all major' + ' browsers like<br>- Firefox<br>- Opera<br>- Safari<br>- Chrome<br>- Internet Explorer 6+',{
'type':'error','title':'Error'}
);
}
);
$('#example2_2').bind('click',function(e){
e.preventDefault();
$.Zebra_Dialog('<strong>Zebra_Dialog</strong> is meant to replace JavaScript\'s <em>alert</em> and <em>confirmation</em>' + ' dialog boxes. <br><br> Can also be used as a notification widget - when configured to show no buttons and to close' + ' automatically - for updates or errors,without distracting users from their browser experience by displaying obtrusive alerts.',{
'type':'warning','title':'Warning'}
);
}
);
$('#example2_3').bind('click',function(e){
e.preventDefault();
$.Zebra_Dialog('<strong>Zebra_Dialog</strong> can generate 5 types of dialog boxes:confirmation,information,' + ' warning,error and question.<br><br>The appearance of the dialog boxes is easily customizable by changing the CSS file ',{
'type':'question','title':'Question'}
);
}
);
$('#example2_4').bind('click',function(e){
e.preventDefault();
$.Zebra_Dialog('<strong>Zebra_Dialog</strong> dialog boxes can be positioned anywhere on the screen - not just in the middle!' + '<br><br>By default,dialog boxes can be closed by pressing the ESC key or by clicking anywhere on the overlay.',{
'type':'information','title':'Information'}
);
}
);
$('#example2_5').bind('click',function(e){
e.preventDefault();
$.Zebra_Dialog('<strong>Zebra_Dialog</strong> is a small (6KB minified),compact (one JS file,no dependencies other than jQuery 1.5.2+)' + ' and highly configurable dialog box plugin for jQuery meant to replace JavaScript\'s <em>alert</em> and <em>confirmation</em> dialog boxes.',{
'type':'confirmation','title':'Confirmation'}
);
}
);
$('#example3').bind('click',function(e){
e.preventDefault();
$.Zebra_Dialog('<strong>Zebra_Dialog</strong>,a small,compact and highly configurable dialog box plugin for jQuery',{
'type':'question','title':'Custom buttons','buttons':['Yes','No','Help'],'onClose':function(caption){
alert((caption != '' ? '"' + caption + '"':'nothing') + ' was clicked');
}
}
);
}
);
$('#example31').bind('click',function(e){
e.preventDefault();
$.Zebra_Dialog('<strong>Zebra_Dialog</strong>,a small,compact and highly configurable dialog box plugin for jQuery',{
'type':'question','title':'Custom buttons','buttons':[{
caption:'Yes',callback:function(){
alert('"Yes" was clicked')}
}
,{
caption:'No',callback:function(){
alert('"No" was clicked')}
}
,{
caption:'Cancel',callback:function(){
alert('"Cancel" was clicked')}
}
]}
);
}
);
$('#example4').bind('click',function(e){
e.preventDefault();
$.Zebra_Dialog('<strong>Zebra_Dialog</strong>,a small,compact and highly configurable dialog box plugin for jQuery',{
'title':'Custom positioning','position':['right - 20','top + 20']}
);
}
);
$('#example5').bind('click',function(e){
e.preventDefault();
new $.Zebra_Dialog('<strong>Zebra_Dialog</strong>,a small,compact and highly configurable dialog box plugin for jQuery',{
'buttons':false,'modal':false,'position':['right - 20','top + 20'],'auto_close':2000}
);
}
);
$('#example6').bind('click',function(e){
e.preventDefault();
$.Zebra_Dialog('<strong>Some dummy content:</strong><br><br>',{
source:{
'ajax':'ajax.html'}
,width:600,title:'External content loaded via AJAX'}
);
}
);
$('#example61').bind('click',function(e){
e.preventDefault();
$.Zebra_Dialog('<strong>A Wikipedia page</strong><br><br>',{
source:{
'iframe':{
'src':'http://en.m.wikipedia.org/wiki/Dialog_box','height':500}
}
,width:800,title:'External content loaded in an iFrame'}
);
}
);
$('#example7').bind('click',function(e){
e.preventDefault();
new $.Zebra_Dialog('Buy me a coffee if you like this plugin!',{
'custom_class':'myclass','title':'Customizing the appearance'}
);
}
);
}
);
CSS代码(style.css):
body{}
/* = MAIN WRAPPER----------------------------------------------------------------------------------------------------------------------*/
.main-wrapper{width:960px;margin:0 auto;text-align:left}
h3{font-size:31px}
h3,p,pre{margin:10px 0}
div.theme{padding:20px;background:#123456;margin:20px 0;color:#FFF}
div.theme a{color:#FFF}
/* = CUSTOM STYLES FOR THE DIALOG BOX----------------------------------------------------------------------------------------------------------------------*/
.myclass .ZebraDialog_Title{background:#330066}
body.flat .myclass .ZebraDialog_Title{background:#DEDEDE;border-bottom:1px solid #222}
.myclass .ZebraDialog_Body{background-image:url('coffee_48.png')}
/* = MISCELLANEOUS----------------------------------------------------------------------------------------------------------------------*/
.align-center{text-align:center}
.align-left{text-align:left}
.align-right{text-align:right}
.block{display:block}
.bottom{margin-bottom:0;padding-bottom:0}
.center{text-align:center}
.clear{clear:both}
.first{margin-left:0;padding-left:0}
.hidden{visibility:hidden}
.highlight{background:#ccf}
.inline{display:inline}
.last{margin-right:0;padding-right:0}
.left{float:left}
.none{display:none}
.nowrap{white-space:nowrap}
.right{float:right}
.stretch{width:100%}
.top{margin-top:0;padding-top:0}
.visible{visibility:visible}