警报/确认/图像/视频/Ajax模式插件 jQuery SimpleModal

  • 源码大小:315.32KB
  • 所需积分:1积分
  • 源码编号:19JP-3394
  • 浏览次数:845次
  • 最后更新:2023年06月08日
  • 所属栏目:幻灯片
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

一个简单的jQuery插件,用于创建可拖动的警报和确认对话框以及图像/视频/AAJAX模式窗口。

在设计网站时,您通常希望显示不同类型的消息或向访问者询问具体信息。有了这个插件,你就可以做到这一点

您可以创建任何类型的警报或确认对话框,甚至可以向访问者提供图像、视频或外部页面作为模式窗口,而无需刷新页面。这使得添加时事通讯、注册或购买表格等内容变得容易。

如何使用它:

1.要开始,请将jQuery SimpleModal插件的文件添加到网页中。

  1. <link rel="stylesheet" href="/path/to/simplemodal.css" />
  2. <script src="/path/to/cdn/jquery.min.js"></script>
  3. <script src="/path/to/simple-modal.js"></script>

2.创建一个警报对话框。

  1. $.fn.SimpleModal({
  2. title: 'Alert Title...',
  3. contents: 'Alert Message...'
  4. })
  5. // show the modal
  6. .showModal();

3.创建一个确认对话框。

  1. $.fn.SimpleModal({
  2. title: 'Confirm Title...',
  3. contents: 'Confirm Message...',
  4. btnOk: 'Confirm button',
  5. model: 'confirm',
  6. callback: function(){
  7. alert('Action confirm!');
  8. },
  9. })
  10. // show the modal
  11. .showModal();

4.创建一个简单的模态窗口。

  1. $.fn.SimpleModal({
  2. model: 'modal',
  3. title: 'Modal Window Title',
  4. contents: '<p>Any HTML Content Here</p>'
  5. })
  6. // add buttons here
  7. .addButton('Confirm', 'btn primary', function() {
  8. alert('Action confirm modal');
  9. this.hideModal();
  10. })
  11. .addButton('Cancel', 'btn')
  12. // show the modal
  13. .showModal();

5.通过AJAX请求将外部页面加载到模式窗口中。

  1. $.fn.SimpleModal({
  2. model: 'modal-ajax',
  3. title: 'Are you sure to delete this?',
  4. param: {
  5. url: 'ajax-content.html',
  6. onRequestComplete: function() { },
  7. onRequestFailure: function() { }
  8. }
  9. })
  10. .addButton('Confirm', 'btn primary', function() {
  11. // check
  12. if( $('confirm-text').get('value') != "DELETE" ) {
  13. $('confirm-delete-error').setStyle('display', 'block');
  14. } else {
  15. // Your code ...
  16. this.hideModal();
  17. }
  18. })
  19. .addButton('Cancel', 'btn')
  20. // show the modal
  21. .showModal();

6.创建一个图像灯箱。

  1. $.fn.SimpleModal({
  2. model: 'modal-ajax',
  3. title: 'Modal Lightbox',
  4. param: {
  5. url: '1.jpg'
  6. }
  7. })
  8. // show the modal
  9. .showModal();

7.将视频(如Youtube和Vimeo)添加到模式窗口中。

  1. $.fn.SimpleModal({
  2. hideFooter: true,
  3. title: 'Vimeo video',
  4. model: 'modal',
  5. contents: '<iframe src="http://player.vimeo.com/video/747666103?title=0&amp;byline=0&amp;portrait=0&amp;color=824571" width="680" height="382" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>'
  6. }).
  7. // show the modal
  8. .showModal();

8.自定义模态的所有默认选项。

  1. $.fn.SimpleModal({
  2. onAppend: null,
  3. offsetTop: null,
  4. overlayOpacity: .3,
  5. overlayColor: '#000000',
  6. width: 400,
  7. draggable: true,
  8. keyEsc: true,
  9. closeButton: true,
  10. hideHeader: false,
  11. hideFooter: false,
  12. animate: true,
  13. btnOk: 'OK',
  14. btnCancel: 'Cancel',
  15. template: '<div class=\"simple-modal-header\"> \
  16. <h1>{_TITLE_}</h1> \
  17. </div> \
  18. <div class=\"simple-modal-body\"> \
  19. <div class=\"contents\">{_CONTENTS_}</div> \
  20. </div> \
  21. <div class=\"simple-modal-footer\"></div>'
  22. }).

预览截图