首页 > 技术文章 > document 屏幕自适应设置

benbenjia 2018-08-30 14:14 原文

<script>
var getPercent = function () {
var percent = '25%';
if (window.innerWidth < 1280) {
percent = '24.9%';
} else if (window.innerWidth <= 1440) {
percent = '19.9%';
} else if (window.innerWidth <= 1600) {
percent = '16.6%';
} else {
percent = '14%';
}
return percent;
}
window.onresize = function () {
$('.ratio-patient-1').css("width", getPercent());
}//监听窗口变化
document.write('<style>.ratio-patient-1{width:' + getPercent() + ' ;}</style>');//自适应宽度
document.write('<style>.tag-1{background:' + BingZhongColor + ' ;}</style>');//病重颜色
</script>

推荐阅读