zoukankan      html  css  js  c++  java
  • JS控制DIV居中对齐

    你真的认为居中对齐那么简单那么我们现在升个级,毕竟要打得怪有点难。。。

    <div id="hz_qxalert1_id" style="position: fixed; top: 0px; left: 0px; right: 0px; bottom: 0px; z-index: 999; display: block; 100%; height: 100%; background: rgba(0, 0, 0, 0.701961);">
    <div id="hz_qxalert1_id_next" style=" 400px; height: 203px; padding: 0px 0px 20px; position: absolute; top: 248px; left: 484px; z-index: 500; border: 1px solid rgb(22, 138, 187); border-radius: 5px; overflow: hidden; display: block; background: rgb(255, 255, 255);">
    <p style="padding: 0 0 0 28px;text-align: left; height:50px; line-height:50px; z-index: 500;">消息会诊</p>
    <hr style="border-color:#ccc; 80%;margin: 0 auto;">
    <p class="alert_text" style="height: 80px; line-height:80px; z-index: 500;text-align: center;">您将取消会诊,确认取消会诊吗?</p>
    <button onclick="enterOut()" class="btn1" style=" z-index: 500;height:30px; outline: none;text-align: center;background: #168ABB;border:0;color:#fff; border-radius:5px; 89px;margin-left: 185px;">是</button>
    <button class="btn1" style="height:30px; outline: none;text-align: center;background: #168ABB;border:0;color:#fff; border-radius:5px; 89px; z-index: 500;">否</button>
    </div>
    </div>

    如这个代码弹出的模态框,怎么样让这个中间白色的块居中对齐,代码如下

    //获取黑色遮罩层的宽、高
    var modelWidth = $('#hz_qxalert1_id').width();
    var modelHeight= $('#hz_qxalert1_id').height();

    //获取取消会诊确认框的宽、高
    var alertWidth = $('#hz_qxalert1_id_next').width();
    var alertHeight= $('#hz_qxalert1_id_next').height();

    //让取消会诊确认框相对于模态框居中
    parent.document.getElementById('hz_qxalert1_id_next').style.left = (modelWidth-alertWidth)/2+"px";
    parent.document.getElementById('hz_qxalert1_id_next').style.top = (modelHeight-alertHeight)/2+"px";

    //让取消会诊的确认框显示出来
    document.getElementById('hz_qxalert1_id_next').style.display = "block";

  • 相关阅读:
    命令模式
    装饰者模式
    迭代器模式-统一集合的遍历方式
    springboot源码解析-管中窥豹系列之总体结构
    启动项目tomcat报错
    在项目中部署redis的读写分离架构(包含节点间认证口令)
    Redis的几个核心机制底层原理
    Java内存模型
    JAVA原子组件和同步组件
    DataGrid 删除一行数据
  • 原文地址:https://www.cnblogs.com/hjptopshow/p/6859814.html
Copyright © 2011-2022 走看看