簡體   English   中英

如何獲取瀏覽器視口的小數寬度和高度?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM