zoukankan      html  css  js  c++  java
  • Bootstrap弹出框(modal)垂直居中

    最近在做一个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了,这样一来就所有的弹出框都垂直居中了。

  • 相关阅读:
    思念
    空白
    curl json string with variable All In One
    virtual scroll list All In One
    corejs & RegExp error All In One
    socket.io All In One
    vue camelCase vs PascalCase vs kebabcase All In One
    element ui 表单校验,非必填字段校验 All In One
    github 定时任务 UTC 时间不准确 bug All In One
    input range & color picker All In One
  • 原文地址:https://www.cnblogs.com/goody9807/p/4488015.html
Copyright © 2011-2022 走看看