抓住浏览器的“缩放” JavaScript中的事件 [英] Catch browser's "zoom" event in JavaScript

查看:525
本文介绍了抓住浏览器的“缩放” JavaScript中的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户更改页面中的缩放时,是否可以使用JavaScript检测?
我只想抓住一个缩放事件并回应它(类似于window.onresize事件)。

Is it possible to detect, using JavaScript, when the user changes the zoom in a page? I simply want to catch a "zoom" event and respond to it (similar to window.onresize event).

谢谢。

推荐答案

没有办法主动检测是否有缩放。我发现一个很好的条目,你可以尝试实现它。

There's no way to actively detect if there's a zoom. I found a good entry here on how you can attempt to implement it.


我发现了两种方法来检测
缩放级别。检测缩放
级别更改的一种方法取决于
百分比值未缩放的事实。 A
百分比值相对于
视口宽度,因此不受
页面缩放的影响。如果您插入两个元素,
一个以百分比的位置,
和一个在
像素中的相同位置,则当
页面缩放时,它们会移开。找到
之间的比例,两个元素的位置和
你有缩放级别。见test
case。
http:// web .archive.org / web / 20080723161031 / http://novemberborn.net/javascript/page-zoom-ff3

您也可以使用上述职位的工具。问题在于您是否大幅度地猜测页面是否缩放。这在一些浏览器中比其他浏览器会更好。

You could also do it using the tools of the above post. The problem is you're more or less making educated guesses on whether or not the page has zoomed. This will work better in some browsers than other.

如果页面在缩放时加载页面,则无法确定页面是否缩放。

There's no way to tell if the page is zoomed if they load your page while zoomed.

这篇关于抓住浏览器的“缩放” JavaScript中的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆