modal-dialog的弹框居中

在做项目时候,需要将bootstrap的modal dialog居中,便查询,网上说直接修改源代码即可

     that.$element
        .show()
        .scrollTop(0)

      that.adjustDialog()

      if (transition) {
        that.$element[0].offsetWidth // force reflow
      }

      that.$element.addClass('in')

      //2015.11.24 modify by lsp modal dialog align center
      var $modalDialog = that.$element.find(".modal-dialog")
        var dialogHeight = $modalDialog.height()
        var windowHeight = $(window).height()

        // When dialog height greater than window height,
        // use default margin top value to set dialog position.
        // if (windowHeight < dialogHeight) {
        // do nothing
        // return;
        // }

        // When dialog height less than window height,
        // use margin top set it position.
        // Dialog position set it with vertical center.
        if (windowHeight > dialogHeight) {
          $modalDialog.css({
            "marginTop": ( windowHeight - dialogHeight) / 2
          });
      }
      //end
      
      that.enforceFocus()

      var e = $.Event('shown.bs.modal', { relatedTarget: _relatedTarget })

  

有时候需要修改modal的属性

$(document).ready(function(){
$('#myModal').modal("hide");
$('#myModal').on('show.bs.modal', function() {//捕获show事件
var dialogWidth = $('.modal-dialog img').get(0).width;
var dialogHeight = $('.modal-dialog img').get(0).height;
$('.modal-dialog').css({
"width":dialogWidth,
"height":dialogHeight
});
})
});

转载于:https://www.cnblogs.com/liushanping/p/4990203.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值