zoukankan      html  css  js  c++  java
  • bootstrap模态框垂直居中

    个人不太建议修改源码,所以,还是写了个方法来用:

    function centerModals() {   
      $('#myModal').each(function(i) {   
        var $clone = $(this).clone().css('display','block').appendTo('body');
        var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 2);
        top = top > 0 ? top : 0;   
        $clone.remove();   
        $(this).find('.modal-content').css("margin-top", top);   
      });   
    };

    用的时候:

    $(function() {
      //页面大小变化是仍然保证模态框水平垂直居中
        $('#myModal').on('show.bs.modal', centerModals);
        $("#enter3-btn").on('click',function(){
          $('#myModal').modal({
            backdrop:'static',
            show:true
          });
        })
        //页面大小变化是仍然保证模态框水平垂直居中
        $(window).on('resize', centerModals);
          
    });
  • 相关阅读:
    IOS-JSON数据解析
    IOS-APP发布资料收集
    IOS-webService
    ASP.NET MVC学习之路:模板页
    io流
    线程
    事件监听
    java基础面试题
    递归调用
    三目运算: x?y:z
  • 原文地址:https://www.cnblogs.com/wang715100018066/p/7884607.html
Copyright © 2011-2022 走看看