bootstrap 模态
<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);
bootstrap 模态的更多相关文章
- js控制Bootstrap 模态框(Modal)插件
js控制Bootstrap 模态框(Modal)插件 http://www.cnblogs.com/zzjeny/p/5564400.html
- Bootstrap模态框按钮
1.触发模态框弹窗的代码 这里复制了一段Bootstrap模态框的代码 <h2>创建模态框(Modal)</h2> <!-- 按钮触发模态框 --> <but ...
- 解决bootstrap模态框内输入框无法获取焦点
bootstrap 模态框中的input标签在某些情况下会无法获取焦点. 最终解决方法:去除模态框的 tabindex="-1" 属性即可
- [原]经典bootstrap模态框使用文章
1,Bootstrap 模态对话框和简单使用 <div id="myModal" class="modal hide fade"> <div ...
- Bootstrap 模态框(Modal)插件
原文链接:http://www.runoob.com/bootstrap/bootstrap-modal-plugin.html Bootstrap 模态框(Modal)插件 模态框(Modal)是覆 ...
- Bootstrap 模态框在用户点击背景空白处时会自动关闭
问题: Bootstrap 模态框在用户点击背景空白处时,会自动关闭. 解决方法: 在HTML页面中编写模态框时,在div初始化时添加属性 aria-hidden=”true” data-backdr ...
- Bootstrap模态弹出窗
Bootstrap模态弹出窗有三种方式: 1.href触发模态弹出窗元素: <a class="btn btn-primary" data-toggle="moda ...
- Bootstrap模态框(MVC)
BZ这篇博客主要是为大家介绍一下MVC如何弹出模态框.本文如果有什么不对的地方,希望大神们多多指教,也希望和我一样的小菜多多学习.BZ在这里谢过各位. 首先要在页面加上一个点击事件: @Html.Ac ...
- 去除bootstrap模态框半透明阴影
当使用bootstrap模态框默认自带半透明阴影,如果想要去除阴影,需要怎么做呢? 今天在项目中我遇到了这个问题,想要去除模态框的阴影,试了好久都没解决.后来问同事的时候才知道,当模态框弹出后,会加上 ...
- bootstrap 模态 modal 小例子
bootstrap 模态 modal 小例子 <html> <head> <meta charset="utf-8" /> <title ...
随机推荐
- 「ZJOI2019」麻将
传送门 Solution 对于条件一:记录一个\(cnt\)表示牌个数\(≥2\)的个数 设\(dp_{i,0/1,j,k}\)表示考虑了\(1...i\),当前是否有对子,以\(i-1\),\(i ...
- SDN阅读作业(二)
前言碎碎念 当我看到这个全英论文以后,身体和心理都出现了戒断反应,让人无比难受,毕竟自己很久没做过英语阅读理解了.总之,在舍友大佬的帮助下以及各款翻译软件的鼎力支持之下(通篇读完后还是找了中文文献来对 ...
- Ecms7.5版CK编辑器保留word格式如何修改
7.5版的编辑器默认会清除多余的word代码,如果要保留word格式怎么修改? CKeditor编辑器默认复制会清除多余word代码,如果要保留word格式可以按下面修改配置: 修改 /e/admin ...
- 刷题记录:[FBCTF2019]Products Manager
目录 刷题记录:[FBCTF2019]Products Manager 一.知识点 1.基于约束的SQL注入攻击 刷题记录:[FBCTF2019]Products Manager 题目复现链接:htt ...
- Qt中文编码和QString类Unicode编码转换
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/g423tgl234/article ...
- 东站七雄保C位!论三线楼市网红板块的自我修养
不对!东站板块才是伍家岗的C位.这里有东站七雄! 前些天发了一篇城东C位之路的文章,居然引发了诸葛说房聊天群内大佬的激烈纷争.公说公有理婆说婆有理,一时争的是不可开交,大有约架之势.所以我决定提前写& ...
- JAVA从服务器下载文件根据Url把多文件打包成ZIP下载
注意: 1. String filename = new String(“xx.zip”.getBytes(“UTF-8”), “ISO8859-1”);包装zip文件名不发生乱码. 2.一定要注意 ...
- android -------- GifImageView 之gif图片加载
目前支持Gif播放的开源库还是有的,试了一下还是这种好用点,所以来分享下android-gif-drawable是通过JNI来渲染帧的,这种方式比使用WebView或者Movie效率要高 要求Andr ...
- [E2E_L9]类化和级联化
一.多车辆识别可能和车辆车牌分割: 这样一张图,可以识别多车辆和车牌,问题是如何区分并且配对. 0 1 7 8 是否是车牌可以通过图片的大小进行判断.而配对是前后顺序的. // ------- ...
- 【转载】 《Human-level concept learning through probabilistic program induction》阅读笔记
原文地址: https://blog.csdn.net/ln1996/article/details/78459060 --------------------- 作者:lnn_csdn 来源:CSD ...