[英]How to get the fractional width and height of the browser viewport?
我不是在談論獲得四舍五入的大小,我需要獲得分數。
我知道的唯一方法是使用position: fixed; top: 0; right: 0, bottom: 0, left: 0
創建一個新的div
元素:已修復; position: fixed; top: 0; right: 0, bottom: 0, left: 0
position: fixed; top: 0; right: 0, bottom: 0, left: 0
屬性設置和 append 完成后它到body
元素,我可以使用getBoundingClientRect
獲得分數大小。
但是它很慢,非常慢。 這種方法會停止執行 rest JS 代碼,直到 DOM 操作和計算完成。
有沒有一種不用昂貴的方法就可以做到這一點的方法?
你可以嘗試使用
let viewPortHeight = window.innerHeight;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.