pop-box-1

实现一个不定宽宽高的弹出窗

by lv san

HTML

<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<div class="box-default">this is a pop that undefinite width and height</div>

CSS

.box-default {
		position: fixed;
		top: 50%;
		left: 50%;
		z-index: 99;
		padding: 20px;
		background-color: white;
		border: 1px solid #ccc;
		border-radius: 8px;
	}

JavaScript

var $box = $('.box-default'),
    bw = $box.width(),
    bh = $box.height();

$box.css({
  marginLeft: - bw/2 + 'px',
  marginTop: - bh/2 + 'px',
});