0

When I try to get HTML element's height by using .height() method while browser is zoomed, the returned value is not valid.

Example:
My element is 35px height with 100% browser zoom, .height() method returns 35px (and it's ok). But when browser zoom is set to 125%, element is now 36.25px height, and .height()method returns 36px, and not exact 36.25px.

Any ideas how to get proper value? Is this a bug, or..?

GileBrt
  • 1,765
  • 2
  • 16
  • 27
Mindfuc
  • 103
  • 1
  • 1
  • 6
  • Please create running code showing problem and why you need a fraction of a pixel. – Juan Mendes Mar 27 '19 at 14:24
  • 3
    Note that sub-pixels generally don't make sense. You cannot color half a pixel, for instance. Your screen can only distinguish physical pixels. – Bram Vanroy Mar 27 '19 at 14:25
  • `.height()` should still return 35, no matter what your zoom is, dependent of using `$('#mydiv').height()` and `document.getelementbyid('myDiv').style.height` (not sure whether those would ever act differently; anyone?) It appears to return 35 no matter what in the latest Firefox. – Elizabeth Mar 27 '19 at 14:27
  • 1
    @EthanJ. `height()` returns the computed height and can not be compared to `element.style.height` or jQuery equivalent `css('height')`. – Mark Baijens Mar 27 '19 at 14:31
  • I think you need to look at https://stackoverflow.com/questions/1713771/how-to-detect-page-zoom-level-in-all-modern-browsers this talks about finding the pixel ratio which in turn is used to get the zoom level. – Saksham Mar 27 '19 at 14:32

0 Answers0