bootstrap添加多个模态对话框支持

(2015-03-04 21:05:35)

标签:

房产

 

因为项目需要,在页面交互上要弹出多个dialog窗口,而bootstrap的modal支持弹出dialog窗口,但是如果在此基础上,会出现遮罩层越来越多,背景越来越黑的情况。

代码具体如下:
(function(){
modal = {};
modal.openDialog = function(url, title, width, height, id){};
modal.closeDialog = function(id){};
window.modal = modal;
})();
 
openDialog函数中传入了id,即为即将生成的dialog的div的id,url为dialog中iframe的src,id也将写在modal函数的参数option中。
 
调用多个dialog时,需要传入不同的id;
源代码中
backdrop: function (callback) {
        var that = this
          , animate = this.$element.hasClass('fade') ? 'fade' : ''
 
        if (this.isShown && this.options.backdrop) {
          var doAnimate = $.support.transition && animate
 
          this.$backdrop = $('

 

')

            .appendTo(document.body)
 
          this.$backdrop.click(
            this.options.backdrop == 'static' ?
              $.proxy(this.$element[0].focus, this.$element[0])
            : $.proxy(this.hide, this)
          )
 
          if (doAnimate) this.$backdrop[0].offsetWidth // force reflow
 
          this.$backdrop.addClass('in')
 
          if (!callback) return
 
          doAnimate ?
            this.$backdrop.one($.support.transition.end, callback) :
            callback()
 
        } else if (!this.isShown && this.$backdrop) {
          this.$backdrop.removeClass('in')
 
          $.support.transition&& this.$element.hasClass('fade')?
            this.$backdrop.one($.support.transition.end, callback) :
            callback()
 
        } else if (callback) {
          callback()
        }
      }
函数中 this.$backdrop = $('

 

').appendTo(document.body)即为添加遮罩层。

 
遮罩层实现为在body后添加,并设置该div的z-Index为99999;
 
我们接下来的实现也是用z-Index,考虑到一层一层网上叠加z-Index,遮罩层只一个即可,而不同的dialog只需比遮罩层的z-Index高即可。
那就仅第一个dialog打开的时候添加遮罩层,其余时候对遮罩层的style中z-Index进行增大即可。
 
在Modal类代码中添加类对象,Modal.ids = [];
 
在进行添加遮罩层时,即var doAnimate = $.support.transition && animate 这行代码后对id进行push,再进行判断dialog个数
dialogId = option.id;
Modal.ids.push(id);
if(Modal.ids.length==1){
this.$backdrop = $('

 

').appendTo(document.body);

$("#"+id).attr("style","z-Index:100000!important");
}else{
var perviouszIndex = $(".modal-backdrop").css("z-Index");
this.$backdrop = $(".modal-backdrop").attr("style","z-Index:"+(perviouszIndex+2)+"!important");
$("#"+id).attr("style","z-Index:"+(perviouszIndex+3)+"!important");
}
而当关闭时,需要对遮罩层的z-Index重新计算,dialog被隐藏了就不需要了,因为再次打开时会再次计算几次
关闭时,对遮罩层的操作在
removeBackdrop: function () {
        this.$backdrop && this.$backdrop.remove()
        this.$backdrop = null
}函数中,改写该函数即可
removeBackdrop: function () {
if(Modal.ids==1)
        this.$backdrop && this.$backdrop.remove();
        this.$backdrop = null;
Modal.ids.shift();
}else{
this.$backdrop.attr("style","z-Index:"+(perviouszIndex-2)+"!important");
Modal.ids.shift();
}
 
以上
 
 
 

bootstrap添加多个模态对话框支持的更多相关文章

  1. 添加一个非模态对话框在revit中

    RequestHandler handler = new RequestHandler(); ExternalEvent exEvent = ExternalEvent.Create(handler) ...

  2. 【2048小游戏】——CSS/原生js爬坑之纯CSS模态对话框&游戏结束

    引言:2048小游戏的结束界面,使用纯CSS制作模态对话框,一般做模态对话框都会使用BootStrap自带的模态对话框组件方便使用,但在制作要运行在移动端的小项目时,就不能使用BootStrap,因为 ...

  3. 为Bootstrap模态对话框添加拖拽移动功能

    请自行下载使用到的Bootstrap库及jQuery库 <!DOCTYPE html> <html> <head lang="en"> < ...

  4. bootstrap导航条+模态对话框+分页样式

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  5. bootstrap表格添加按钮、模态框实现

    bootstrap表格添加按钮.模态框实现 原创 2017年07月20日 17:35:48 标签: bootstrap 1723 bootstrap表格添加按钮.模态框实现 - 需求: 需要表格后面每 ...

  6. Bootstrap 模态对话框只加载一次 remote 数据的解决办法 转载

    http://my.oschina.net/qczhang/blog/190215 摘要 前端框架 Bootstrap 的模态对话框,可以使用 remote 选项指定一个 URL,这样对话框在第一次弹 ...

  7. bootstrap模态对话框

    bootstrap模态对话框 前提是引入bootstrap的css和js的东西 data-backdrop="static"代表的是点击旁边的内容,不进行关闭操作,但是esc的时候 ...

  8. jQuery练习 | 模态对话框(添加删除)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. 一百二十六:CMS系统之轮播图管理页面布局和添加轮播图的模态对话框制作

    视图 @bp.route('/banners/')@login_required@permission_required(CMSPersmission.POSTER)def banners(): re ...

随机推荐

  1. Netty 100万级高并发服务器配置

    前言 每一种该语言在某些极限情况下的表现一般都不太一样,那么我常用的Java语言,在达到100万个并发连接情况下,会怎么样呢,有些好奇,更有些期盼. 这次使用经常使用的顺手的netty NIO框架(n ...

  2. Möbius strip

    en.wikipedia.org/wiki/Möbius_strip http://mechproto.olin.edu/final_projects/average_jo.html Fabricat ...

  3. 什么是aop?-------转

    什么是AOP?  http://www.cnblogs.com/zhugenqiang/archive/2008/07/27/1252761.html#commentform(转) AOP(Aspec ...

  4. xml 基础属性

    xml属性 对应的方法 说明 android:alpha setAlpha(float) 设置组件的透明度(0——1) android:background setBackgroundResource ...

  5. 远程请求json数据,list中显示

    public class MainActivity extends Activity { protected static final int WHAT_REQUEST_SUCCESS = 1; pr ...

  6. hdu1078 FatMouse and Cheese —— 记忆化搜索

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 代码1: #include<stdio.h>//hdu 1078 记忆化搜索 #in ...

  7. 用 Flotr2 实现的 HTML5 图表

    1. [图片] 未命名.jpg ​2. [代码][HTML]代码 <!DOCTYPE html><html lang="en" >    <head& ...

  8. 手把手教你打造ImageView支持手势放大缩小

    写在前面 最近有了新的任务,学习的时间比以前少了不少,Java回炉的文估计是得缓缓了,不过每周一篇尽量保质保量.最近感觉我文写的有点不好,因为我写东西除非必要,不然概念性的东西我基本上都是一笔带过…… ...

  9. .NET CORE2.0后台管理系统(一)配置API

    一:引用关系图 要写一个项目首先离不开的就是一个清晰的流程图,当然我这里很简单. 上诉完成后打开api下的Startup.cs文件,因为我是配置好了所在我直接上传代码然后介绍一下: using Sys ...

  10. 1336 : Matrix Sum (hihocoder)

    题目链接: 点击打开链接 二维树状数组,百度一大堆,我只是存代码的 #include<stdio.h> #include<iostream> #include<algor ...