博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
bootstrap 模态
阅读量:4686 次
发布时间:2019-06-09

本文共 2679 字,大约阅读时间需要 8 分钟。

<script type="text/javascript" src="js/jquery-ui-custom.min.js"></script>  //这个js里主要是需要用到jquery.ui.draggable.js,但是这个js需要依赖其他的js,所以我直接上jquery-ui的官网上根据自己的需要生成

这样子,一个基本的bootstrap模态框就写好了,但是现在的模态框只是水平居中,而且是不能拖拽的,所以还要进行一些处理。

//设置模态框可移动 这里用到上面引入的jquery-ui-custom.min.js$(#id).draggable({       handle: ".modal-header",       cursor: 'move',       refreshPositions: false});                        //模态框居中显示function centerModals() {       $(#id).each(function(i){          var $clone = $(this).clone().css('display', 'block').appendTo('body');        //设置modal垂直居中        var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 2);           top = top > 0 ? top : 0;           $(this).find('.modal-content').css("margin-top", top);        $clone.remove();           });}$(window).on('resize', centerModals);

  还要修改bootstrap.css中的一个样式

.modal-backdrop {  position: absolute;  top: 0;  right: 0;  left: 0;  background-color: #000;}

  

.modal-backdrop {  position: fixed;  top: 0;  right: 0;  left: 0;  bottom: 0;  background-color: #000;}

  由于我需要用到很多不同的模态框,打开和关闭的时候都需要执行一些动作

/** * 初始化模态窗口 * @param modalName 模态窗口id * @param showBcak show时执行的方法 * @param hideBcak hide时执行的方法 */function modalInit(modalName,showBcak,hideBcak){    var modalName = '#' + modalName;    //设置模态框可移动    $(modalName).draggable({           handle: ".modal-header",           cursor: 'move',           refreshPositions: false    });            //模态框居中显示    function centerModals() {           $(modalName).each(function(i){              var $clone = $(this).clone().css('display', 'block').appendTo('body');            //设置modal垂直居中            var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 2);               top = top > 0 ? top : 0;               $(this).find('.modal-content').css("margin-top", top);            $clone.remove();                   });    }    //调用show方法时触发    $(modalName).on('show.bs.modal', function(){        if (null != showBcak && "" != showBcak) {            var funcBack = eval(showBcak);            new funcBack();        }        centerModals();    });    //调用hide方法时触发    $(modalName).on('hide.bs.modal', function(){        if (null != hideBcak && "" != hideBcak)        {            var funcBack = eval(hideBcak);            new funcBack();        }            });    $(window).on('resize', centerModals);  }

  Bootstrap模态框水平垂直居中与增加拖拽功能

http://www.panshy.com/articles/201509/webdev-2524.html
  Bootstrap 模态框(Modal)插件
http://www.dnzs.com.cn/w3cschool/bootstrap/bootstrap-modal-plugin.html

调用

http://files.cnblogs.com/files/zzd-zxj/model.rar

1 modalInit("demoModal", null,null);

转载于:https://www.cnblogs.com/xiangxiong/p/7168799.html

你可能感兴趣的文章
程序的跳转(一行代码)
查看>>
hello world ,详解
查看>>
Update
查看>>
DataGridView ScrollBar End Event
查看>>
C#委托的一次"甜蜜"接触
查看>>
前端开发值得推荐的各种资源
查看>>
MYSQL5.7版本sql_mode=only_full_group_by问题
查看>>
使用JavaScript为一张图片设置备选路径
查看>>
httpclient4.5.2 Post请求支持http和https
查看>>
HDU之旅
查看>>
Sql2005:provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接
查看>>
SQL Server主键自动生成_表and存储过程
查看>>
selenium无法正常运行 Chrome浏览器,cannot find Chrome binary的问题
查看>>
一体机分区误删找到数据的方案
查看>>
excel常用函数
查看>>
网络协议-restful协议
查看>>
JavaScript模块化编程(一)
查看>>
egg文件制作与安装
查看>>
后台测试流程与经验分享
查看>>
EventBus 最简易的使用方式
查看>>