Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#12594 closed bug (duplicate)

width() returns float when zoomed

Reported by: [email protected] Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.8.2
Keywords: Cc:
Blocked by: Blocking:


http://api.jquery.com/width/ says that width() is supposed to return integers only, but in Chrome and Firefox it is returning floating-point values if the page is zoomed. IE does not exhibit this problem for me.


<!doctype html>
<script src='jquery-1.8.2.min.js'></script>
  $(document).ready(function() {
    setInterval(function() {
    }, 30);
  <div id='div' style='width:300px; height:300px; border: solid'></div>

In chrome & firefox, if I zoom in/out (ctrl+ and ctrl-), I expect the number displayed to stay 300, but instead it changes to 299.3333330154419, 299.9909906387329, 300.5454545021057, etc.

  • jquery 1.8.2
  • win7 64bit
  • chrome 22.0.1229.64 beta-m
  • firefox 14.0.1

Change History (6)

comment:1 Changed 9 years ago by [email protected]

Sorry, I didn't see the note about using jsFiddle until after I posted. Here's the same sample:


comment:2 Changed 9 years ago by Rick Waldron

Resolution: duplicate
Status: newclosed

Duplicate of #11298.
jQuery only supports use in 100% zoom

comment:3 Changed 9 years ago by [email protected]

Is there a canonical place where the "only supports 100% zoom" policy is documented? It is a surprise to me and I've been using jquery for years. I'm also unable to find it mentioned outside of passing references in bugs.

Are there any suggested workarounds other than just popping up a warning like "sorry your zoom level is not supported?"

comment:4 Changed 9 years ago by Rick Waldron

That's exactly the problem, there is no way to know if the viewport is zoomed. It doesn't need to be "canonically documented" as it's not a jQuery issue.

comment:5 Changed 9 years ago by [email protected]

I had no way to know jQuery wouldn't work with zoom, though. It isn't written down anywhere outside of bugs. I would have been less confused (and wouldn't have bothered to open this bug) if the API docs mentioned that zoom led to undocumented behavior. That said, I would understand if this is deemed too esoteric an issue to warrant mentioning in the docs, though.

I also would have been helped by knowing that other methods of getting the width (such as .css(width) and .clientWidth) work correctly when zooming in chrome & FF.

comment:6 Changed 9 years ago by mikesherov

I opened this ticket against the docs to see if they'll add a note about zoom not working well: https://github.com/jquery/api.jquery.com/issues/76

Note: See TracTickets for help on using tickets.