Bootstrap弹出框(modal)垂直居中
2015-05-08 16:19
477 查看
最近在做一个eit项目,由于此项目里面一些框架要遵循nttdata的一些规则,故用到了Bootstrap这个东东,第一次碰到这个东东,有很大抵触,觉得不好,但用起来我觉得和别的弹出框真没什么两样。废话少说,切入正题,Bootstrap弹出框垂直居中的问题,因为我拿到的弹出框样式并非垂直居中,而是top 10%,但页面长了,就显得特别恶心。
解决方案:
1.在css里,找到
.modal.fade.in {
top: 10%;
}
这个样式,修改它就ok了,由于css中是全局的,同时也可在页面中定义到某个modal的(高度)位置,方法如下:
<style>
#myModal-help
{
top:300px;
}
</style>
#myModal-help这个为modal的id,这样设置就ok了。
2.在js中,
我用的是bootstrap-modal.js(如果用的是bootstrap.js或者是bootstrap.min.js,同样可以,但需要找到相应位置)。
在js中找到(红色是我添加的方法):
var left = ($(document.body).width() - that.$element.width()) / 2;
var top = ($(document.body).height() - that.$element.height()) / 2;
var scrollY = document.documentElement.scrollTop || document.body.scrollTop; //滚动条解决办法
var top = (window.screen.height / 4) + scrollY - 120; //滚动条解决办法
console.log(left);
that.$element
.addClass('in')
.attr('aria-hidden', false)
.css({
left: left,
top: top,
margin: "0 auto"
});
that.enforceFocus()
找到后,将红色的添加进去,就ok了,这样一来就所有的弹出框都垂直居中了。
解决方案:
1.在css里,找到
.modal.fade.in {
top: 10%;
}
这个样式,修改它就ok了,由于css中是全局的,同时也可在页面中定义到某个modal的(高度)位置,方法如下:
<style>
#myModal-help
{
top:300px;
}
</style>
#myModal-help这个为modal的id,这样设置就ok了。
2.在js中,
我用的是bootstrap-modal.js(如果用的是bootstrap.js或者是bootstrap.min.js,同样可以,但需要找到相应位置)。
在js中找到(红色是我添加的方法):
var left = ($(document.body).width() - that.$element.width()) / 2;
var top = ($(document.body).height() - that.$element.height()) / 2;
var scrollY = document.documentElement.scrollTop || document.body.scrollTop; //滚动条解决办法
var top = (window.screen.height / 4) + scrollY - 120; //滚动条解决办法
console.log(left);
that.$element
.addClass('in')
.attr('aria-hidden', false)
.css({
left: left,
top: top,
margin: "0 auto"
});
that.enforceFocus()
找到后,将红色的添加进去,就ok了,这样一来就所有的弹出框都垂直居中了。
相关文章推荐
- Bootstrap 弹出框modal 垂直居中(适用各种分辨率窗口)
- Bootstrap弹出框(modal)垂直居中的问题及解决方案详解
- Bootstrap弹出框(modal)垂直居中
- bootstrap modal弹出框的垂直居中
- Bootstrap弹出框(modal)垂直居中
- bootstrap modal弹出框的垂直居中
- Bootstrap 模态框(modal)实现水平垂直居中显示
- bootstrap 模态框(modal)实现水平垂直居中显示 含具体分析
- bootstrap 弹出框modal添加垂直方向滚轴效果
- Bootstrap(v3.2.0)模态框(modal)垂直居中
- Bootstrap模态框(modal)垂直居中
- bootstrap弹出框垂直居中
- bootstrap modal 垂直居中对齐
- bootstrap modal垂直居中
- Bootstrap模态框(modal)垂直居中
- bootstrap modal垂直居中
- bootstrap 模态框(modal)实现水平垂直居中显示的方法
- bootstrap modal垂直居中
- bootstrap 模态框(modal)实现水平垂直居中显示
- Bootstrap modal不能垂直居中的解决办法