[英]I want to know when the browser “viewport” resizes
I've just realized that we could specify @media screen and (min-width:x) and (max-width:y)
我刚刚意识到我们可以指定
@media screen and (min-width:x) and (max-width:y)
What I'm trying to do is to detect when the browser "viewport" resizes, I was thinking is there anyway we could abuse the @media functionality (since it definitely could detect when the browser window resizes) and hook an event handler to handle the browser window resize?我想要做的是检测浏览器“视口”何时调整大小,我在想我们是否可以滥用@media 功能(因为它肯定可以检测到浏览器 window 何时调整大小)并挂钩事件处理程序来处理浏览器 window 调整大小?
I was thinking we have something like this (example):我在想我们有这样的东西(例子):
@media screen and (min-width:400px){#tracker{top:400px;}}
@media screen and (min-width:800px){#tracker{top:800px;}}
@media screen and (min-width:1200px){#tracker{top:1200px;}}
@media screen and (min-width:1600px){#tracker{top:1600px;}}
@media screen and (min-width:2000px){#tracker{top:2000px;}}
Then have a Javascript function that runs every 200 milliseconds or so (that function will keep track of #tracker's top value and hence we can "detect" a browser resize.然后有一个每 200 毫秒左右运行一次的 Javascript function (即 function 将跟踪“检测”#tracker 的调整大小,因此我们可以跟踪浏览器的大小调整。
<body onResize="jsFunction();">
Is this what you're looking for?这是你要找的吗?
Also note that window
also has an onresize method, ie window.resize
in javascript还要注意
window
还有一个 onresize 方法,即window.resize
中的 window.resize
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.