JS控制DIV置中對齊

來源:互聯網
上載者:User

標籤:擷取   rgba   ack   isp   mod   cli   padding   osi   center   

你真的認為置中對齊那麼簡單那麼我們現在升個級,畢竟要打得怪有點難。。。

<div id="hz_qxalert1_id" style="position: fixed; top: 0px; left: 0px; right: 0px; bottom: 0px; z-index: 999; display: block; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.701961);">
<div id="hz_qxalert1_id_next" style="width: 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;width: 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;width: 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;width: 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";

JS控制DIV置中對齊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.