jquery 彈出框自適應視窗垂直水平居中
阿新 • • 發佈:2019-01-02
<html>
<head>
<title>彈出框自適應</title>
<script src="jquery-1.10.2.min.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
*{
margin: 0;
padding: 0;
border: 0;
}
.pop{
position : fixed;
padding: 10px 20px;
border: solid pink 1px;
}
</style>
<script type="text/javascript">
$(function(){
function boxAuto(){
var dom = $(".pop");
var w = dom.innerWidth();
var h = dom.innerHeight();
var t = ($(window).height() - h) / 2;
var l = ($(window).width() - w) / 2;
dom.css("top",t);
dom.css("left",l);
}
boxAuto();
$(window).resize(function(){
boxAuto();
})
});
</script >
</head>
<body style="height:1000px;">
<div class="pop">
彈出框
</div>
</body>
</html>