Which Javascript method/code or trick can determine the largest element between them, so if current window is smaller, I can execute if sentence to reduce this big image to fit window
Asked
Active
Viewed 34 times
0
-
2Why not just use CSS to set the maximum size of the image to be the size of the window? I.e. [CSS background image to fit width, height should auto-scale in proportion](https://stackoverflow.com/q/9262861/215552) – Heretic Monkey May 13 '20 at 19:48
-
You might have to do that manually. if you're using jQuery, ```$(window).width()``` gets the width of the window and for an element ```$('#my_element').width()``` returns the width of that element. So you can produce an ```if``` statement to check against a certain size of the window, then resize the element accordingly – Cypherjac May 13 '20 at 19:50
-
jquery isn't necessary, this can be done with HTML alone, using window.innerWidth and window.innerHeight to get window size and Element.offsetWidth and Element.offsetHeight to get an element's size. – shannon May 13 '20 at 23:19
-
@shannon effect is identical if body or html tag measurements are taken ? – ephesinus May 14 '20 at 16:09
-
If the normal methods are not working for you you should include your code demonstrating the issue. – shannon May 14 '20 at 16:46
-
I Work with an old browser but it works very well – ephesinus May 14 '20 at 17:55