对话框 弹出层

HTML代码

<button class="btn radius btn-primary size-L" onClick="modaldemo()">弹出对话框</button>

弹出层代码

<div id="modal-demo" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content radius">
<div class="modal-header">
<h3 class="modal-title">对话框标题</h3>
<a class="close" data-dismiss="modal" aria-hidden="true" href="javascript:void();">×</a>
</div>
<div class="modal-body">
<p>对话框内容…</p>
</div>
<div class="modal-footer">
<button class="btn btn-primary">确定</button>
<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
</div>
</div>
</div>
</div>

CSS代码

.fade {opacity: 0;
  -webkit-transition: opacity .15s linear;
  -o-transition: opacity .15s linear;
  transition: opacity .15s linear}
.fade.in {opacity: 1}
.modal-open {overflow: hidden}
.modal{ position:fixed; left:0; top:0; right:0; bottom:0; z-index:1040; display:none; overflow:hidden;-webkit-overflow-scrolling:touch; outline:0}
.modal.fade .modal-dialog{
  -webkit-transition: -webkit-transform .3s ease-out;
  -o-transition: -o-transform .3s ease-out;
  transition: transform .3s ease-out;
  -webkit-transform: translate(0,-50%);
  -ms-transform: translate(0,-50%);
  -o-transform: translate(0,-50%);
  transform: translate(0,-50%)}
.modal.in .modal-dialog {
  -webkit-transform: translate(0, 0);
  -ms-transform: translate(0, 0);
  -o-transform: translate(0, 0);
  transform: translate(0, 0)}
.modal-open .modal {overflow-x: hidden;overflow-y: auto}
  .modal-backdrop {position: fixed;top: 0;right: 0;bottom: 0;left: 0;background-color: #000}
  .modal-backdrop.fade {filter: alpha(opacity=0);opacity: 0}
  .modal-backdrop.in {filter: alpha(opacity=50);opacity: .5}
  .modal-dialog {position: relative;width: auto;margin: 10px}
  .modal-content{position: relative;background-color: #fff;border: 1px solid #999;border: 1px solid rgba(0,0,0,.2);outline: 0;
    -webkit-background-clip: padding-box;
    background-clip: padding-box;
    -webkit-box-shadow: 0 3px 9px rgba(0,0,0,.5);
    box-shadow: 0 3px 9px rgba(0,0,0,.5)}

    .modal-header {min-height: 16.42857143px;padding: 15px;border-bottom: 1px solid #eee; position:relative}
    .modal-header .close{position:absolute; right:10px; top:10px}
    .modal-header h3,.modal-header .modal-title{margin:0; padding:10px 0; font-size:16px}

    .modal-body {position:relative;padding: 15px;overflow-y:visible;word-break:break-all}
      .modal-form {margin-bottom: 0}

    .modal-footer {padding:15px;margin-bottom: 0;text-align: right;background-color: #f5f5f5;border-top: 1px solid #eee;*zoom: 1}
    .modal-footer:before,.modal-footer:after {display: table;content: ""}
    .modal-footer:after {clear: both}
    .modal-footer .btn + .btn {margin-left: 5px;margin-bottom: 0}
    .modal-footer .btn-group .btn + .btn {margin-left: -1px}
    .modal-footer .btn-block + .btn-block {margin-left: 0}

  .modal-scrollbar-measure {position: absolute;top: -9999px;width: 50px;height: 50px;overflow: scroll}

  .radius .modal-content{ border-radius:6px}
  .radius .modal-footer{ border-bottom-left-radius:6px; border-bottom-right-radius:6px}
  @media (min-width: 768px) {
    .modal-dialog {width: 600px;margin: 30px auto}
    .modal-content {-webkit-box-shadow: 0 5px 15px rgba(0, 0, 0, .5);box-shadow: 0 5px 15px rgba(0, 0, 0, .5)}
    .modal-sm {width: 300px}
  }
  @media (min-width: 992px) {
    .modal-lg {width: 900px}
  }

.modal-alert{position:fixed; right:auto; bottom:auto; width:300px; left:50%;margin-left:-150px; top:50%;margin-top:-30px; z-index:9999;background-color: #fff;border: 1px solid #999;border: 1px solid rgba(0,0,0,.2);outline: 0;
  -webkit-background-clip: padding-box;
  background-clip: padding-box;
  -webkit-box-shadow: 0 3px 9px rgba(0,0,0,.5);
  box-shadow: 0 3px 9px rgba(0,0,0,.5)}
.modal-alert-info{padding:30px; text-align:center; font-size:14px; background-color:#fff}
      

JS代码

引入jquery.js 和 H-ui.js

模态弹出窗默认支持的自定义属性主要有:

属性 类型 默认值 描述 备注
backdrop 布尔值 true 点击背景是否关闭模态框,true关闭,false不关闭 等价于data-backdrop
keyboard 布尔值 true 按ESC是否关闭模态框,true关闭,false不关闭 等价于data-keyboard
show 布尔值 true 初始化时弹出框是否显示 等价于data-show

参数

参数 使用方法 描述
toggle $(“#mymodal”).modal(“toggle”) 触发时,反转模态弹出窗的状态。如果模态弹出窗是显示的,则关闭;反之,如果模态弹出窗是关闭的,则显示
show $(“#mymodal”).modal(“show”) 触发时,显示模态弹出窗
hide $(“#mymodal”).modal(“hide”) 触发时,关闭模态弹出窗

事件设置

模态弹出窗还支持四种类型的事件,分别是模态弹出窗的弹出前、弹出后,关闭前、关闭后,具体描述如下:

事件类型 描述
show.bs.modal 在show方法调用时立即触发(尚未显示之前);如果单击了一个元素,那么该元素将作为事件的relatedTarget属性
shown.bs.modal 该事件在模态弹出窗完全显示给用户之后(并且等CSS动画完成之后)触发;如果单击了一个元素,那么该元素将作为事件的relatedTarget事件
hide.bs.modal 在hide方法调用时(但还未关闭隐藏)立即触发
hidden.bs.modal 该事件在模态弹出窗完全隐藏之后(并且CSS动画漂完成之后)触发

调用方法也非常简单:

function modaldemo(){
  $("#modal-demo").modal("show")
}
function modalalertdemo() {
  $("body").Huimodalalert({
    content: '我是消息框,2秒后我自动滚蛋!',
    speed: 2000
  })
}

Copyright ©2013-2022 H-ui.net All Rights Reserved.
豫ICP备19019279号-1
H-ui只是一个纯web前端的程序,没有后台和数据库,也不提供任何系统代运营服务。所有使用H-ui开发的任何系统版权都归开发者所有,造成的任何损失、不良影响,H-ui均不承担任何法律责任。
未经允许,禁止转载、抄袭、镜像
用心做站,做不一样的站