在网上看到有Bootstrap2的Modal dialog垂直居中问题解决方法,这种方法自己试了一下,并不能完全居中,并且窗口的大小不一样的话,每次显示的margin-top值也会改变,遮盖层还会出现滚动条,效果也不好看,代码如下:

  1. //在初始显示时设置垂直居中
  2. $('#YourModal').modal().css({
  3. 'margin-top': function () {
  4. return -($(this).height() / 2);
  5. }
  6. });
  7. //或者我们可以将这个效果注册到显示事件中:
  8. $('.modal').on('show', function() {
  9. $(this).css({
  10. 'margin-top': function () {
  11. return -($(this).height() / 2);
  12. }
  13. });
  14. });

今天正好遇到这个问题,不过我用的Bootstrap框架是Bootstrap3版本了,解决代码如下:

  1. $('#YourModal').on('show.bs.modal', function (e) {
  2. $(this).find('.modal-dialog').css({
  3. 'margin-top': function () {
  4. var modalHeight = $('#yourModal').find('.modal-dialog').height();
  5. return ($(window).height() / 2 - (modalHeight / 2));
  6. }
  7. });
  8. });  

Bootstrap modal垂直居中的更多相关文章

  1. bootstrap modal 垂直居中对齐

    bootstrap modal 垂直居中对齐   文章参考 http://www.bubuko.com/infodetail-666582.html http://v3.bootcss.com/Jav ...

  2. bootstrap modal垂直居中(简单封装)

    1.使用modal 弹出事件方法: 未封装前: <!DOCTYPE html> <html lang="en"> <head> <meta ...

  3. Bootstrap Modal 垂直居中

    Bootstrap 的 modal 正文中如果内容较少的话,并不会垂直居中,而是偏上, 如果想要达到垂直居中的效果,需要自动动手了. 可以在初始显示时设置垂直居中,可以这样做: $('#YourMod ...

  4. bootstrap modal垂直居中 (转)

    根据博友的经验,总结后请使用方法一就行了 一,修改bootstrap.js 源码 原来的: Modal.prototype.adjustDialog = function () { ].scrollH ...

  5. Bootstrap模态框(modal)垂直居中

    http://v3.bootcss.com/ 自己也试了改了几种方式也不容乐观,发现在窗口弹出之前是获取不到$(this).height()的值,本想着是用($(window).height()-$( ...

  6. Bootstrap(v3.2.0)模态框(modal)垂直居中

    Bootstrap(v3.2.0)模态框(modal)垂直居中方法: 在bootstrap.js文件900行后面添加如下代码,便可以实现垂直居中. that.$element.children().e ...

  7. bootstrap Modal 模态框垂直居中

    解决 Modal 垂直居中的问题,上网找了好多博客,有好多说改源码的,这个并没有实践. 但发现另一种解决办法,可以实现,代码如下: function centerModals(){ $('.modal ...

  8. Bootstrap3模态框Modal垂直居中样式

    1,Bootstrap 模态框插件Bootbox垂直居中样式: <!DOCTYPE html> <html lang="en"> <head> ...

  9. Bootstrap Modal 垂直方向加滚动条

    原文链接:http://blog.csdn.net/cyh1111/article/details/52960747 背景 使用Bootstrap Modal实现用户资料修改,由于用户信息过多,默认M ...

随机推荐

  1. org.apache.commons.lang.StringUtils中常用的方法

    org.apache.commons.lang.StringUtils中常用的方法,这里主要列举String中没有,且比较有用的方法: 1. 检查字符串是否为空: static boolean isB ...

  2. Collection类相关总结

    集合类的框架如下: Collection(接口)    List(接口):允许重复.         ArrayList         Vector         LinkedList    Se ...

  3. Some Delphi tips

    ====================================conversion routines====================================Format('T ...

  4. firefox, chrome常见插件

    firefox: firebug flagfox adblock autoproxy foxyproxy firegestures httpfox httprequester colorzilla j ...

  5. JVM初探 -JVM内存模型

    JVM初探 -JVM内存模型 标签 : JVM JVM是每个Java开发每天都会接触到的东西, 其相关知识也应该是每个人都要深入了解的. 但接触了很多人发现: 或了解片面或知识体系陈旧. 因此最近抽时 ...

  6. hash-4.hashtable

    1.先看hashtable的源代码 public synchronized V put(K key, V value) { // Make sure the value is not null if ...

  7. 修改Mysql默认编码

    show variables like 'character%';+--------------------------+----------------------------+| Variable ...

  8. Javascript高级程序设计——面向对象之实现继承

    原型链: 构造函数中都有一个prototype属性指针,这个指针指向原型对象,而创建的实例也有指向这个原型对象的指针__proto__.当实例查找方法时先在实例上找,找不到再通过__proto__到原 ...

  9. 6. 终端工具Xmanager使用技巧

    1. 新建绘画使用终端连接服务器 2. 设置终端类型和编码 3. 设置终端外观,包括字体颜色等等 4. 设置默认上传路径和下载路径

  10. [POJ1177]Picture

    [POJ1177]Picture 试题描述 A number of rectangular posters, photographs and other pictures of the same sh ...