失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 每次页面大小更改 实时获取屏幕宽度

每次页面大小更改 实时获取屏幕宽度

时间:2021-08-28 13:59:12

相关推荐

每次页面大小更改 实时获取屏幕宽度

<script> (function () {function w() {var all = document.documentElement; //获取html元素var test = all.getBoundingClientRect().width; //获取当前设备的宽度、console.log('宽度', test) if (test < 1000) {document.querySelector('.aaa').style.display = 'none'document.querySelector('.bbb').style.display = 'block'} else {document.querySelector('.aaa').style.display = 'block'document.querySelector('.bbb').style.display = 'none' } rem = test / 18.75;all.style.fontSize = rem + 'px'}w();window.addEventListener("resize", function () {w()}, false)})();</script>

<script>//在iphone6 375宽度中 html是以20px作为基本单位(function () {function w() {var all = document.documentElement; //获取html元素var test = all.getBoundingClientRect().width; //获取当前设备的宽度、console.log(123, test)if (test > 750) {test = 750;}rem = test / 18.75;console.log(rem)all.style.fontSize = rem + 'px'}w();window.addEventListener("resize", function () {w()}, false)})();</script>

如果觉得《每次页面大小更改 实时获取屏幕宽度》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。