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. ffmpeg ffplay播放延时大问题:播放延时参数设置

    使用ffplay播放视频源时,rtsp/rtmp等,会有一定的延时,这里我们可以通过设置ffplay播放参数将延时控制到最小. ffplay.exe -i rtmp://xxxxxxx -fflags ...

  2. IE浏览器 get请求缓存问题

    场景: 比较简单是使用的SpringMVC框架,在做资源国际化的时候,遇到了这个问题.具体做的操作是在页面上点击切换语言的时候,需要发起请求在Controller中切换Locale. 问题: 1.开始 ...

  3. Ext rowcontextmenu回调

    今天栽了大跟头,,,, EXT js右键可以获取到选中的那一列的索引值,只需在回调函数中取到那一列的数据就可以ok,不用再费尽心思的费用执行click的事件 grid.on("rowcont ...

  4. MYSQL进阶学习笔记十六:MySQL 监控!(视频序号:进阶_35)

    知识点十七:MySQL监控(35) 一.为什么使用MySQL监控 随着软件后期的不断升级,myssql的服务器数量越来越多,软硬件故障的发生概率也越来越高.这个时候就需要一套监控系统,当主机发生异常时 ...

  5. Android-低功耗蓝牙(BLE)-客户端(主机/中心设备)和服务端(从机/外围设备)

    一.Android 低功耗蓝牙(BLE)的API简介 从Android 4.3(API 18)才支持低功耗蓝牙(Bluetooth Low Energy, BLE)的核心功能, BLE蓝牙协议是GAT ...

  6. hdu-5728 PowMod(数论)

    题目链接: PowMod Time Limit: 3000/1500 MS (Java/Others)     Memory Limit: 262144/262144 K (Java/Others) ...

  7. Keras 可视化 model

    参考:https://keras.io/visualization/ error解决参考:http://blog.csdn.net/wangjian1204/article/details/50346 ...

  8. 「CQOI2007」「BZOJ1260」涂色paint (区间dp

    1260: [CQOI2007]涂色paint Time Limit: 30 Sec  Memory Limit: 64 MBSubmit: 2057  Solved: 1267[Submit][St ...

  9. bootstrap table 根据单元格中的数据改变单元格的样式

    在bootstrap-table.js里面列属性 formatter就是用来格式化单元格的,其默认值是undefined 类型是function,function(value,  row, index ...

  10. 文件的打开函数第一类--fopen()

        fopen函数用来打开一个文件,其调用的一般形式为: 文件指针名=fopen(文件名,使用文件方式); 其中, “文件指针名”必须是被说明为FILE 类型的指针变量: “文件名”是被打开文件的 ...