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. 登录和注册(Js)的写法

    今天在做小组项目的时候发现登录和注册的使用不是很熟,记录下来: <script> //弹出框中的css部分 input { font-family: Arial, sans-serif;} ...

  2. 有返回值的Bookmark

    首先代码创建Activity: public sealed class WaitForResponse<TResult>:NativeActivity<TResult> { p ...

  3. mybatis是什么?(二)

    mybatis是什么? mybatis是一个持久层的框架,是apache下的顶级项目. mybatis托管到goolecode下,再后来托管到github下(https://github.com/my ...

  4. DuiLib笔记之Control常用属性

    name 指定控件名称,同一窗口内必须唯一,类型:STRING float 用于指定控件是否使用绝对定位,或设置FloatPercent,类型:BOOL,默认值为false,格式:float=&quo ...

  5. Detours3.0 文档翻译

    http://blog.csdn.net/buck84/article/details/8289991 拦截二进制函数 Detours库能够在执行过程中动态拦截函数调用.detours将目标函数前几个 ...

  6. php设计模式之--组合模式

    php组合模式主要用于上下级关系,可以新增叶子和树枝,分析如下代码即可明白组合模式的含义: <?php header('Content-Type:text/html;charset=utf-8' ...

  7. dij+堆优化

    写这个dij+堆优化的原因是有些地方卡SPFA,只能搞这个: 香甜的奶油: #include<iostream> #include<cstdio> #include<cs ...

  8. Eclipse快捷键【转载】

    分享一前辈的博客-Eclipse快捷键

  9. UVa 11572 唯一的雪花(优化策略)

    题目描述: 输入一个长度为n(n<=1000000)的序列A, 找到一个尽量长的连续子序列A(L)-->A(R),是的该序列中没有相同的元素. 输入: T:代表组数 n:代表有n个数 这一 ...

  10. 安装Nginx四层负载均衡

    Nginx1.9开始支持tcp层的转发,通过stream实现的,而socket也是基于tcp通信. stream模块默认不安装的,需要手动添加参数:–with-stream,官方下载地址:downlo ...