强大 jQuery对话框插件 Zebra_Dialog

  • 源码大小:219.23KB
  • 所需积分:1积分
  • 源码编号:19JP-3802
  • 浏览次数:1289次
  • 最后更新:2023年07月24日
  • 所属栏目:其他
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

Zebra_Dialog是一个小型(缩小了4KB)、紧凑(一个JS文件,除了jQuery 1.5.2+之外没有其他依赖项)和高度可配置的jQuery对话框插件。它也可以用作网站或项目的通知小部件。

Zebra_Dialog可以生成6种类型的对话框:确认、信息、警告、提示、错误和问题。通过更改CSS文件,可以很容易地自定义对话框的外观。

Zebra_Dialog对话框可以放置在屏幕上的任何位置,而不仅仅是中间!默认情况下,可以通过按ESC键或单击覆盖上的任意位置来关闭对话框。它也可以用作网站或项目的通知小部件。

根据GNU宽松通用公共许可证v3.0许可。

您可能还喜欢:

  • 用于Bootstrap的jQuery对话框插件-Bootbox
  • 现代模态对话框-ModalBox
  • 轻量级模态对话框插件-SimpleModal
  • 模态对话框Windows插件-leanModal
  • SimpleModal-漂亮的弹出窗口插件

基本用法:

1.在您的网页上包含jQuery库和jQuery Zebra_Dialog。

  1. <script src="jquery.min.js"></script>
  2. <script src="javascript/zebra_dialog.js"></script>

2.包含jQuery Zebra_Dialog来设计插件的样式。

  1. <link rel="stylesheet" href="css/zebra_dialog.css" type="text/css">

3.Html标记。

  1. <a href="javascript:void(0)" id="example1">here</a>

4.调用插件并完成。

  1. // show a dialog box when clicking on a link
  2. $('#example1').bind('click', function(e) {
  3. e.preventDefault();
  4. $.Zebra_Dialog('The link was clicked!');
  5. });

5.可能的带有默认值的插件选项。

  1. // The speed, in milliseconds, by which the overlay and the
  2. // dialog box will be animated when closing.
  3. animation_speed_hide: 250,
  4.  
  5. // The speed, in milliseconds, by which the dialog box will
  6. // fade in when appearing.
  7. animation_speed_show: 0,
  8.  
  9. // The number of milliseconds after which to automatically
  10. // close the dialog box or FALSE to not automatically close the dialog box.
  11. auto_close: false,
  12.  
  13. // The index (0-based) of the button (from left to right) to
  14. // place the focus on when a dialog box is first shown.
  15. //
  16. // Set to FALSE to disable. When set to FALSE the focus will
  17. // be placed on the dialog box's content so that when the
  18. // users presses TAB, the focus will be set on the first
  19. // button.
  20. //
  21. // Setting this to TRUE is equivalent to setting it to 0.
  22. auto_focus_button: true,
  23.  
  24. // Use this for localization and for adding custom buttons.
  25. //
  26. // If set to TRUE, the default buttons will be used, depending
  27. // on the type of the dialog box: ['Yes', 'No'] for "question"
  28. // type and ['Ok'] for the other dialog box types.
  29. //
  30. // For custom buttons, use an array containing the captions of
  31. // the buttons to display: ['My button 1', 'My button 2'].
  32. //
  33. // Set to FALSE if you want no buttons.
  34. //
  35. // Note that when the dialog box is closed as a result of clicking
  36. // a button, the "onClose" event is triggered and the callback
  37. // function (if any) receives as argument the caption of the
  38. // clicked button.
  39. //
  40. // See the comments for the "onClose" event below for more
  41. // information.
  42. //
  43. // You can also attach callback functions to individual buttons
  44. // by using objects in the form of:
  45. //
  46. // [
  47. // {caption: 'My button 1', callback: function() { // code }},
  48. // {caption: 'My button 2', callback: function() { // code }}
  49. // ]
  50. //
  51. // The main difference is that a callback function attached this
  52. // way is executed as soon as the button is clicked rather than
  53. // *after* the dialog box is closed, as it is the case with the
  54. // "onClose" event.
  55. //
  56. // Callback functions attached to buttons get as argument the
  57. // entire dialog box jQuery object.
  58. //
  59. // A callback function returning FALSE will prevent the dialog
  60. // box from closing.
  61.  
  62. // When set to TRUE, the buttons will be centered instead of
  63. // right-aligned.
  64. buttons: true,
  65.  
  66. // When set to TRUE, the buttons will be centered instead of
  67. // right-aligned.
  68. center_buttons: false,
  69.  
  70. // An extra class to add to the dialog box's container. Useful
  71. // for customizing a dialog box elements' styles at runtime.
  72. //
  73. // For example, setting this value to "mycustom" and in the
  74. // CSS file having something like
  75. // .mycustom .ZebraDialog_Title { background: red }
  76. // would set the dialog box title's background to red.
  77. //
  78. // See the CSS file for what can be changed.
  79. custom_class: false,
  80.  
  81. // By default, the height of the dialog box is automatically
  82. // set and it is also influenced by the "max_height" property.
  83. //
  84. // Use this to set a fixed height, in pixels, for the dialog
  85. // box.
  86. height: 0,
  87.  
  88. // When set to TRUE, pressing the ESC key will close the dialog
  89. // box.
  90. keyboard: true,
  91.  
  92. // Margin of the dialog box relative to the viewport's limits
  93. // (a single value, applied both horizontally and/or vertically)
  94. //
  95. // This is used when the dialog box is stretched 100% horizontally
  96. // and/or vertically and "width" and "max_width" are not set
  97. // (when stretched horizontally) and "height" and "max_height"
  98. // are not set (when stretched vertically).
  99. //
  100. // Can be specified as a numeric value (which will be interpreted
  101. // as a value in pixels) or as a percentage (of the viewport).
  102. //
  103. // Default is "0" - when stretched, the dialog box sticks to
  104. // the viewport's limits.
  105. margin: 0,
  106.  
  107. // The maximum height, in pixels, before the content in the
  108. // dialog box is scrolled.
  109. //
  110. // If set to "0" the dialog box's height will automatically
  111. // adjust to fit the entire content.
  112. max_height: 0,
  113.  
  114. // The maximum width of the dialog box.
  115. //
  116. // Can be specified as a numeric value (which will be interpreted
  117. // as a value in pixels) or as a percentage (of the viewport).
  118. //
  119. // If "max_width" is set to valid value greater than 0,
  120. // then the "width" property will be ignored.
  121. max_width: 450,
  122.  
  123. // Default value to show in the input box when the dialog
  124. // box type is "prompt".
  125. default_value: '',
  126.  
  127. // The text (or HTML) to be displayed in the dialog box.
  128. //
  129. // See the "source" property on how to add content via AJAX,
  130. // iFrames or from inline elements.
  131. message: '',
  132.  
  133. // When set to TRUE there will be a semitransparent overlay
  134. // behind the dialog box, preventing users from clicking
  135. // the page's content.
  136. modal: true,
  137.  
  138. // Should the dialog box close when the overlay is clicked?
  139. overlay_close: true,
  140.  
  141. // A selector indicating the DOM element to server as the overlay's container.
  142. overlay_container: 'body',
  143.  
  144. // The opacity of the overlay (between 0 and 1)
  145. overlay_opacity: '.9',
  146.  
  147. // Position of the dialog box.
  148. //
  149. // Can be either "center" (which would center the dialog box) or
  150. // an array with 2 elements, in the form of
  151. // {'horizontal_position +/- offset', 'vertical_position +/- offset'}
  152. // (notice how everything is enclosed in quotes) where
  153. // "horizontal_position" can be "left", "right" or "center",
  154. // "vertical_position" can be "top", "bottom" or "middle", and
  155. // "offset" represents an optional number of pixels to add/substract
  156. // from the respective horizontal or vertical position.
  157. //
  158. // Positions are relative to the viewport (the area of the
  159. // browser that is visible to the user)!
  160. //
  161. // Examples:
  162. //
  163. // ['left + 20', 'top + 20'] would position the dialog box in the
  164. // top-left corner, shifted 20 pixels inside.
  165. //
  166. // ['right - 20', 'bottom - 20'] would position the dialog box
  167. // in the bottom-right corner, shifted 20 pixels inside.
  168. //
  169. // ['center', 'top + 20'] would position the dialog box in
  170. // center-top, shifted 20 pixels down.
  171. position: 'center',
  172.  
  173. // The duration (in milliseconds) of the animation used to
  174. // reposition the dialog box when the browser window is resized.
  175. reposition_speed: 500,
  176.  
  177. // When set to TRUE, a "close" button (the little "x") will be
  178. // shown in the upper right corner of the dialog box.
  179. //
  180. // If the dialog box has a title bar then the "close" button
  181. // will be shown in the title bar, vertically centered and
  182. // respecting the right padding.
  183. //
  184. // If the dialog box does not have a title bar then the "close"
  185. // button will be shown in the upper right corner of the body
  186. // of the dialog box, respecting the position related properties
  187. // set in the stylesheet.
  188. show_close_button: true,
  189.  
  190. // Add content via AJAX, iFrames or from inline elements (together
  191. // with the already applied events).
  192. //
  193. // This property can be any of the following:
  194. //
  195. // - 'ajax': object - where "object" can be an object with any
  196. // of the properties you'd normally use to make an AJAX call in
  197. // jQuery (see the description for the "settings" argument at
  198. // http://api.jquery.com/jQuery.ajax/), or it can be a string
  199. // representing a valid URL whose content to be fetched via
  200. // AJAX and placed inside the dialog box.
  201. //
  202. // Example:
  203. //
  204. // source: {'ajax': 'http://myurl.com/'}
  205. //
  206. // source: {'ajax': {
  207. // 'url': 'http://myurl.com/',
  208. // 'cache': false
  209. // }}
  210. //
  211. // Note that you cannot use the "success" property as it will
  212. // always be overwritten by the library; use the "complete"
  213. // property instead, if you have to!
  214. //
  215. // - 'iframe': object - where "object" can be an object where
  216. // property names can be valid attributes of the <iframe> tag
  217. // (see https://developer.mozilla.org/en-US/docs/HTML/Element/iframe),
  218. // or it can be a string representing a valid URL to be loaded
  219. // inside an iFrame and placed inside the dialog box.
  220. //
  221. // Example:
  222. //
  223. // source: {'iframe': 'http://myurl.com/'}
  224. //
  225. // source: {'iframe': {
  226. // 'src': 'http://myurl.com/',
  227. // 'width': 480,
  228. // 'height': 320,
  229. // 'scrolling': 'no'
  230. // }}
  231. //
  232. // Note that you should always set the iFrame's width and height
  233. // and adjust the dialog box's "width" property accordingly!
  234. //
  235. // - 'inline': selector - where "element" is a jQuery element
  236. // from the page; the element will be copied and placed inside
  237. // the dialog box together with any attached events! if you just
  238. // want the element's inner HTML, use $('#element').html().
  239. //
  240. // Example:
  241. //
  242. // source: {'inline': $('#myelement')}
  243. source: false,
  244.  
  245. // Title of the dialog box
  246. title: '',
  247.  
  248. // Dialog box type.
  249. //
  250. // Can be any of the following:
  251. //
  252. // - confirmation
  253. // - error
  254. // - information
  255. // - question
  256. // - warning
  257. // - prompt
  258. // If you don't want an icon, set the "type" property to FALSE.
  259. //
  260. // By default, all types except "question" have a single button
  261. // with the caption "Ok"; type "question" has two buttons, with
  262. // the captions "Ok" and "Cancel" respectively.
  263. type: 'information',
  264.  
  265. // Should short messages be vertically centered?
  266. vcenter_short_message: true,
  267.  
  268. // By default, the width of the dialog box is set in the CSS
  269. // file. Use this property to override the default width at
  270. // runtime.
  271. //
  272. // Must be an integer, greater than 0. Anything else will instruct
  273. // the script to use the default value, as set in the CSS file.
  274. // Value should be no less than 200 for optimal output.
  275. width: 0,
  276.  
  277. // Event fired when *after* the dialog box is closed.
  278. //
  279. // For executing functions *before* the closing of the dialog
  280. // box, see the "buttons" attribute.
  281. //
  282. // The callback function (if any) receives as argument the
  283. // caption of the clicked button or boolean FALSE if the dialog
  284. // box is closed by pressing the ESC key or by clicking on the
  285. // overlay.
  286. onClose: null

6.在对话框关闭后执行一个功能。

  1. var dialog = new $.Zebra_Dialog('This is some information');
  2.  
  3. // First argument: the caption of the clicked button or boolean FALSE if the dialog box is closed by pressing the ESC key, by clicking the dialog box's x button, or by clicking the overlay. The argument can also be boolean TRUE when the dialog box type is prompt and the ENTER key is pressed while inside the input box.
  4. // Second argument: receives the value entered in the input box - when the dialog box type is prompt and a button was clicked or the ENTER key was pressed while inside the input box, or undefined for any other case.
  5. dialog.on('onClose', function(arguments){
  6. // do something
  7. })

7.以编程方式隐藏/更新对话框。

  1. var dialog = new $.Zebra_Dialog('This is some information');
  2.  
  3. dialog.close();
  4. dialog.update();

更新日志:

2021-11-24

  • 代码格式

3.0.5版(2020-08-19)

  • 修复了使用iFrame时的错误

3.0.4版(2020-08-18)

  • 修复了3.0.0中引入的disable_page_scrolling属性对没有滚动的页面产生不良影响的错误

版本3.0.3(2020-07-19)

  • SASS文件现在可以在dist文件夹中使用
  • 修复了重叠对话框的中断示例

3.0.2版(2020-04-26)

  • 只在示例中添加屏幕截图的小版本

3.0.1版(2020-03-31)

  • 修复了“center_buttons”属性在最新版本中不居中按钮的问题

v3.0.0(2019年9月04日)

  • 打开的对话框后面的页面滚动现在默认禁用
  • 添加了margin属性,以防止对话框在水平和/或垂直拉伸100%时触及视口的限制
  • 添加了max_width属性,该属性与现有的max_height属性一起,现在可以指定为百分比
  • 添加了用于提示类型对话框的default_value属性
  • 宽度和高度属性现在也可以指定为百分比
  • custom_class现在也被添加到覆盖中,而不仅仅是对话框中
  • 当指定垂直位置(中间位置旁边)时,也可以使用单词中心
  • 使用iFrame时,现在会自动计算宽度和高度,以适应对话框的宽度和高度;此外,现在在加载iFrame内容时还显示了一个微调器
  • 现在,当打开多个模式对话框时,库会自动进行后台管理
  • 放弃IE6支持
  • 修复了对话框位置不正确的错误,它有边框
  • 删除了backrop_container属性
  • 对所有模板进行小调整

v2.1.1版本(2019-06-04)

  • 添加了提示对话框类型
  • 添加了用于为对话框设置自定义高度的高度属性
  • 添加了更新方法,用于在运行时动态更改内容时调整对话框的位置
  • 通过新添加的overlay_container属性,覆盖现在可以拥有与body元素不同的父元素

v2.1.0版本(2019-06-04)

  • 在以前的提交中中断的固定高度

v2.0.0版本(2018-08-01)

  • 添加了一个新的“auto_focus_button”属性,用于指示首次显示对话框时要放置焦点的按钮
  • 简化对话框的HTML标记和指示对话框的各种状态/设置的所有类现在都添加到了主容器中
  • 以前在JavaScript中完成的一些对齐现在在CSS中完成,但仍在IE6中工作:)
  • 完全重写了主题的CSS,我们现在使用干净的CSS来优化CSS输出,导致平面主题减少了0.5KB,经典主题减少了1.8KB
  • 添加了一个新的实体化主题,灵感来自谷歌材料设计

v1.6.0 (2018-07-26)

  • “警告”对话框现在有“是”和“否”按钮,而不仅仅是“确定”按钮
  • 将“确认”对话框上按钮的标签从“是”和“否”更改为“确定”和“取消”
  • 修改后的示例页面

v1.5.0 (2018-07-05)

  • 修复了对话框中的输入永远无法集中在移动设备上的错误
  • 修复了插件在IE8中不工作的问题
  • 自定义类现在可以添加到按钮中
  • 添加了版本号作为公共属性-即使您只有缩小的源代码,也有助于查找版本号

2018-07-04

  • 自定义类现在可以添加到按钮中

v1.4.1 (2017-10-14)

  • 修复了对话框高度可能超过视口高度的错误
  • 修复了iPhone上的滚动

v1.4.0(2016年6月28日)

  • 性能改进和源代码调整
  • 新文件夹结构
  • 对话框现在在小屏幕上有100%的宽度

v1.3.12 (2016-06-01)

  • 修复了“关闭”按钮的定位问题

v1.3.8 (2013-12-21)

  • 修复了一个错误

v1.3.7 (2013-11-26)

  • 添加了新的“平面”主题

v1.3.6 (2013-10-17)

  • 固定参考
  • 修复了2个错误

v1.3.3 (2013-05-29)

  • 现在可以从CSS设置覆盖和对话框的z索引值。以前,这些都是在JavaScript代码中设置的,需要破解源代码才能更改它们;

v1.3.2 (2013-05-27)

  • 修复了一个错误,即如果“reposition_speed”属性>0,并且手动调整浏览器窗口的大小,则用于重新定位窗口的动画将排队,并将进程减慢到几乎完全停止;
  • 将“animaton_speed”属性的名称更改为“animation_speed_hide”,并添加了一个新的“animatia_speed_show”,用于设置对话框出现时淡入的速度;

v1.3.1 (2013-05-07)

  • 修复了“框大小”设置为“边框框”的错误

 

预览截图