tombigel / detect-zoom

Cross Browser Zoom and Pixel Ratio Detector
http://tombigel.github.io/detect-zoom/
535 stars 122 forks source link

Idea check the client width of a known Element #53

Open Drtikso opened 10 years ago

Drtikso commented 10 years ago

Has anyone thought of this?

<div id="test">H</div><br/>
<div id="content" style="background-color:cyan; width:50%;">BLAH<div/>
</body>
<script>
function work(){
var w = screen.width;
var content = document.getElementById("content");
var width = content.clientWidth;
var height = content.clientHeight;
document.getElementById("test").innerHTML = width + " " + height + " " + w;
}
setInterval(work,60);
</script>

var w doesn't change it's value when the page is zoomed. var width changes.

Some Maths and voila :smile:

curiousercreative commented 4 years ago

unfortunately, screen.width updates as you zoom in Firefox for one.