bootstrap 模态框(modal)实现水平垂直居中显示的方法
来源:互联网 发布:切诺基2700发动机数据 编辑:程序博客网 时间:2024/05/22 01:50
众所周知,bootstrap是一款非常实用的CSS框架(主要用于样式的快速搭建),由于其简洁,美观,快捷,响应式等特点备受大家喜欢,但是其本身也是存在很多bug,当应对与具体的业务逻辑的时候往往达不到细节要求,比如今天我要谈的bootstrap的模态框,其默认是显示距离顶端30px,左右居中。
怎么让其在垂直方向也居中呢?
大家可能想加一个CSS样式,让其距离顶部距离变长,实践是检验真理的唯一标准,当你去试过会发现很多问题,在不修改源码的前提下修改插件并没有自由配置的样式一直是前端人员头疼的事情,在此,我百度了下百度到两个方法
出处Altaba的博客
$('#youModel').on('shown.bs.modal', function (e) css('display'{ var modalHeight=$(window).height() / 2 - $('#youModel .modal-dialog').height() / 2; $(this).find('.modal-dialog').css({ 'margin-top': modalHeight }); });
会出现问题,每次触发事件让模态框显示的时候,会闪动一下,影响体验,在此查阅资料在此基础上提出完善的方法2
$('#youModel').on('shown.bs.modal', function (e) { // 关键代码,如没将modal设置为 block,则$modala_dialog.height() 为零 $(this).css('display', 'block'); var modalHeight=$(window).height() / 2 - $('#youModel .modal-dialog').height() / 2; $(this).find('.modal-dialog').css({ 'margin-top': modalHeight }); });
// 将事件监听的事件改成show.bs.modal 即可解决 $('#youModel').on('show.bs.modal', function (e) { // 关键代码,如没将modal设置为 block,则$modala_dialog.height() 为零 $(this).css('display', 'block'); var modalHeight=$(window).height() / 2 - $('#youModel .modal-dialog').height() / 2; $(this).find('.modal-dialog').css({ 'margin-top': modalHeight }); });
这样就可以解决闪动问题并完美居中了!
阅读全文
0 0
- bootstrap 模态框(modal)实现水平垂直居中显示的方法
- Bootstrap 模态框(modal)实现水平垂直居中显示
- bootstrap 模态框(modal)实现水平垂直居中显示 含具体分析
- Bootstrap模态框(modal)垂直居中
- Bootstrap模态框(modal)垂直居中
- Bootstrap modal 模态框垂直居中
- bootstrap模态框(modal)垂直居中
- bootstrap modal垂直居中
- bootstrap modal 垂直居中
- bootstrap modal垂直居中
- Bootstrap模态框水平垂直居中
- bootstrap modal弹出框的垂直居中
- Bootstrap modal不能垂直居中的解决办法
- bootstrap modal垂直居中(转)
- 实现垂直水平居中的方法
- bootstrap modal 垂直居中对齐
- bootstrap modal 垂直居中对齐
- bootstrap modal 垂直居中对齐
- RecyclerView长按事件
- 研究生课程 算法分析-分治法
- Java集合之LinkedList源码分析
- top和ps取长补短之top中ps所不具备的进程监控功能之i选项
- spark源码部署到eclipse之SBT安装部署
- bootstrap 模态框(modal)实现水平垂直居中显示的方法
- 怎样安装Python3
- POJ 1486
- 搜索
- 计算网络osi七层模型
- Fx3U PLC操作M寄存器问题点记录
- 应聘大学教师,超实无穷小功不可没!
- 简单接口回调
- hex 模拟题