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 ...
随机推荐
- git常用命名:自用,持续更新
1.切换分支 git checkout -b dev origin/feature/迭代1.1 2.提交本地代码到github git init //初始化git git config --globa ...
- 刷题记录:[ByteCTF 2019]EZCMS
目录 刷题记录:[ByteCTF 2019]EZCMS 一.知识点 1.源码泄露 2.MD5长度扩展攻击 3.php://filter绕过正则实现phar反序列化 刷题记录:[ByteCTF 2019 ...
- 第06组 Alpha冲刺(2/4)
队名:福大帮 组长博客链接:https://www.cnblogs.com/mhq-mhq/p/11885037.html 作业博客 :https://edu.cnblogs.com/campus/f ...
- 单细胞数据normalization方法 | SCTransform
SCTransform Normalization and variance stabilization of single-cell RNA-seq data using regularized n ...
- 《精通CSS第3版》(5)漂亮的盒子
- filebeat获取nginx的access日志配置
filebeat获取nginx的access日志配置 产生nginx日志的服务器即生产者服务器配置: 拿omp.chinasoft.com举例: .nginx.conf主配置文件添加日志格式 log_ ...
- ISO/IEC 9899:2011 条款6——语言
6 语言 6.1 标记法 1.在本条款中所使用的语法标记法.语义类别(非终结符)用斜体字指示,而字面量单词以及字符集成员(终结符)用粗体字指示.跟在一个非终结符后面的冒号(:)引出其定义.在单独的行中 ...
- Python3基础 dict __len__ 统计键值对的数量
Python : 3.7.3 OS : Ubuntu 18.04.2 LTS IDE : pycharm-community-2019.1.3 ...
- Robotics Education and Research at Scale - A Remotely Accessible Robotics Development Platform
张宁 Robotics Education and Research at Scale - A Remotely Accessible Robotics Development Platform链接 ...
- Spring MVC -- Spring MVC入门
本篇博客首先介绍Spring MVC的优点,然后介绍Spring MVC的基本组件,包括DispatcherServlet,并学习如何开发一个“传统风格”的控制器,这是在Spring 2.5版本之前开 ...