无论浏览器缩放如何,查找以像素为单位的 CSS 值
我做了一个小的 JS 小提琴来演示我的问题。当您使用浏览器放大和缩小页面时,记录到控制台的 max-width
值会发生变化,但在 CSS 中它总是为 500 像素。无论是否放大,如何找到原始 CSS 值,例如 max-width
?
I have made a small JS fiddle to demonstrate my problem. When you zoom in and out of the page with your browser, the max-width
value that is being logged to the console changes, but in the CSS it is always going to be 500px. How can I find the original CSS value, for instance max-width
, regardless of if you're zoomed in or not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后我不得不使用(这个 JavaScript 插件)[https://github.com/yonran/detect-zoom/],它提供了缩放级别。为了计算原始 CSS 值,我只需乘以缩放级别:
例如,如果浏览器放大到 2 级:
这当然会返回 500px 的原始像素值。
In the end I had to use (this JavaScript plugin)[https://github.com/yonran/detect-zoom/] which provides the zoom level. In order to calculate the original CSS value, I just multiplied by the zoom level:
For instance, if the browser was zoomed in at the level of 2:
Which of course would return the original pixel value of 500px.