检测视口大小调整时出现问题
我正在开发一个需要垂直边框的项目,目前垂直边框是根据页面大小或页面长度(取决于哪一个较长)计算的,但有一个小问题。
我正在使用 Firefox,例如,如果我的 noscript
插件启动并且我允许该脚本,则垂直边框将在页面底部出现间隙。
举个例子,有什么方法可以使用 javascript 来检测跨多个浏览器的视口更改吗?
我在某个地方找到了 watch() ,但无法找到有关它的可靠文档以及哪些浏览器支持它。我想做的事情可能吗? watch()
是正确的方法吗?如果是这样,有人可以向我指出一些文档吗?如果不是,我应该看什么?
I'm working on a project that requires that the vertical borders, which are currently calculated based on page size or the length of the page depending on which one is longer, but there is a slight issue.
I am using Firefox and for example if my noscript
plugin kicks in and I for example allowed the script the vertical borders will have a gap at the bottom of the page.
That as an example, is there any way I am able to use javascript to detect a viewport change across multiple browsers?
I found somewhere watch()
but was unable to find solid documentation on it and what browsers support this. Is what I am trying to do possible? Is watch()
the proper way? If so, can anyone point me to some documentation, if not, what should I be looking at?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为
window.onresize
是您正在寻找的事件。这是一个链接: https://developer.mozilla.org/en/DOM/window.onresize但是,您应该能够仅使用 CSS 来获取全高元素,然后您将不需要任何 javascript
window.onresize
is the event you're looking for, I think. Here's a link: https://developer.mozilla.org/en/DOM/window.onresizeHowever, you should be able to get full-height elements using only CSS, and then you won't need any javascript
也许您可以使用媒体查询和
window.matchMedia
来解决这个问题https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
https://hacks. mozilla.org/2012/06/using-window-matchmedia-to-do-media-queries-in-javascript/
Maybe you can solve this problem with Media Queries and
window.matchMedia
https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
https://hacks.mozilla.org/2012/06/using-window-matchmedia-to-do-media-queries-in-javascript/