您的位置:首页 > 运维架构

【原创】相对完美的垂直居中popup(modal/dialog),无需监听window.resize事件

2015-07-31 15:38 525 查看
<table class="popup" style="position: absolute; background-color: black; border-radius: 10px; top: 50%; left: 50%;">
<tr>
<td>
<div>
<textarea style="margin:10px;  background-color:azure;  height:150px;width:100px;" contenteditable="true"></textarea>
</div>
</td>
</tr>
</table>


$(function () {
var $popup = $('.popup');
$popup.css({marginLeft: $popup.width() / 2 * -1 + 'px', marginTop: $popup.height() / 2 * -1 + 'px' });
});


使用table的目的是,模拟弹窗的高度会根据弹窗的内容高度显示。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: