您的位置:首页 > 其它

根据不同分辨率显示相同web页面

2017-12-14 17:16 239 查看
<script>

changeSize();

window.onresize = function() {

changeSize();

};

function changeSize() {

let newWidth = Number(window.innerWidth);
let newHeight = Number(window.innerHeight);

var appBox = document.querySelector('.container');

if(newWidth > 1920) {

// appBox.style.left = (newWidth - 1920) / 2 + 'px';
// //appBox.style.top = (newHeight - 1080)/2 + 'px';
// appBox.style.top = ((newWidth / 1920 - 1) * 1080) / 2 + 'px';
appBox.style.transformOrigin = '0 0';
appBox.style.transform = 'scale(' + newWidth / 1920 + ',' + newWidth / 1920 + ')';
appBox.style.width = (1920 / newWidth) * 100 + '%';
appBox.style.height = (1080 / newHeight) * 100 + '%';

}

if(newWidth <= 1920) {

appBox.style.transformOrigin = '0 0';
appBox.style.transform = 'scale(' + newWidth / 1920 + ',' + newWidth / 1920 + ')';
appBox.style.width = (1920 / newWidth) * 100 + '%';
appBox.style.height = (1080 / newHeight) * 100 + '%';

}

}
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐