光年模板说明文档
主题
字号
18px

模态框最大化

这里旨在对模态框增加最大化的功能(因为是模态框的原因,在保留模态框的一些样式基础上做最大化处理)。css和绑定事件的js可以放到通用的文件当中,模态框新增最大化按钮即可。

模态框原有的关闭图标后增加最大化图标按钮,3和4的版本在html上有些许区别(modal-fullscreen-btn)。 v3版本:

<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <button type="button" class="modal-fullscreen-btn pull-right m-r-5"><i class="mdi"></i></button>
    <h4 class="modal-title" id="myModalLabel">标题</h4>
</div>

v4版本:

<div class="modal-header">
  <h6 class="modal-title" id="myModalLabel">标题</h6>
  <div class="float-right">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
      <span aria-hidden="true">&times;</span>
    </button>
    <button type="button" class="modal-fullscreen-btn"><i class="mdi"></i></button>
  </div>
</div>

新增样式:

.modal-fullscreen-btn {
    border: none;
    background-color: transparent;
    text-shadow: 0 1px 0 #fff;
    color: #000;
    opacity: 0.2;
    font-size: 16px;
    line-height: 1.3;
    font-weight: 700;
}
.modal-fullscreen-btn .mdi:before {
    content: "\f293";
}
.modal-fullscreen-btn:hover {
    opacity: .5;
}
.modal-fullscreen {
    padding-left: 0px!important;
}
.modal-fullscreen .modal-fullscreen-btn {
    opacity: .8;
}
.modal-fullscreen .modal-fullscreen-btn .mdi:before {
    content: "\f294";
}
.modal-fullscreen .modal-dialog {
    width: -webkit-calc(100% - 20px);
    width: calc(100% - 20px);
    max-width: calc(100% - 20px);
    margin: 8px auto;
}
.modal-fullscreen .modal-dialog .modal-body {
    height: -webkit-calc(100vh - 56px - 69px - 20px);
    height: calc(100vh - 56px - 69px - 20px);
    overflow-y: auto;
}

新增js:

$(document).ready(function() {
    $(document).on('click', '.modal-fullscreen-btn', function(){
        $(this).closest('.modal').toggleClass('modal-fullscreen');
    });
});

因为这里做演示用,所以用了 $(document).ready(function(){});,如果放到 main.min.js 里面的时候,去掉这一层,把里面的 click 事件绑定放进去。

;jQuery( function() {
    // 内容放到这里
});

插件项目中页面名字:test_modal_maximize.html test_modal_maximize_v4.html

点击查看 模态框最大化 在线演示