<!DOCTYPE html>
<html style="height: 100%;">
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="js/jquery/jquery.min.js"></script>
</head>
<body style="height: 100%;">
<div id="transDiv" style="height: 1584px; width: 5880px;">
<h1>测试页面代码,页面像素大小根据分辨率自由压缩</h1>
<div class="cicle" style="width: 550px; height: 550px;-webkit-border-radius: 275px; -moz-border-radius: 275px; border-radius: 275px; background: red;"></div>
</div>
</body>
</html>
<script>
$(document).ready(function(){
transPage();
})
/**
* 界面自化缩放
* 注意:html和body标签都需要增加 class="height100" 才可自由压缩页面
*/
function transPage(){
let windowWidth = document.body.offsetWidth;
let pageWidth = $("#transDiv").outerWidth();
let rateX = windowWidth / pageWidth;
let marginLeft = (pageWidth * (1-rateX)) / 2;
let windowHeight = document.body.offsetHeight;
let pageHeight = $("#transDiv").outerHeight();
let rateY = windowHeight / pageHeight;
let marginTop = (pageHeight * (1-rateY)) / 2;
$("#transDiv").css("transform","scale(" +rateX + " , " + rateY +")");
$("#transDiv").css("margin-left",-marginLeft + "px");
$("#transDiv").css("margin-top",-marginTop + "px");
$("html").css({
"overflow-y" : "hidden", "overflow-x": "hidden"
});
}
</script>