I want to know when the browser viewport is resized

I just realized that we can point @media screen and (min-width:x) and (max-width:y)

What I'm trying to do is determine when the browser "viewport" resizes, I thought that in any case, we could abuse the functionality of @media (since it can definitely detect when the browser window resizes) and hook the event handler for resizing the browser window?

I thought we had 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 there is a Javascript function that works every 200 milliseconds or so (that the function will track the #tracker of the upper value and, therefore, we can "detect" the browser resize.

+3
source share
1 answer
<body onResize="jsFunction();">

, ?

, window onresize, .. window.resize javascript

+3