0

Is there an event that I can access when the user zooms on a page? I'd like to fix the placement of an element when the user zooms.

<div id='a'> </div>
<div id='b'> </div>

<script type="text/javascript">
   var right = $('#a').offset().right;
   $('#a').css('right',right);
</script>

I'd place this code in the event for zooming.

user823527
  • 3,214
  • 15
  • 57
  • 106
  • 2
    possible duplicate of [Catch browser's "zoom" event in JavaScript](http://stackoverflow.com/questions/995914/catch-browsers-zoom-event-in-javascript) – Crozin Apr 20 '12 at 01:12

1 Answers1

2

You can attempt hacks to try to detect this, but in reality they don't want developers to have access to this because you could just write code to defeat the purpose of the zoom. E.G. shrinking elements so they fit, even though a user is trying to enlarge the elements because they have bad eyesight, or something similar. This concept even applies for mobile devices, you cannot truly detect whether or not someone has pinch zoomed on an iphone, etc. The methods you will find include positioning elements and listening for changes, but this won't help if the user is zoomed when the page loads, and even if they aren't it still is not fool proof.

So short answer, no there is no window.zoom event similar to window.resize.

user1289347
  • 2,412
  • 1
  • 11
  • 16
  • On an iPhone at least, zooming can be disabled through minimum and maximum scale settings in a *meta* element, preventing the user from zooming. Same for orientation change (landscape/portrait). Annoying as hell, but some just don't want you to zoom their pages. – RobG Apr 20 '12 at 02:19
  • Yes, I hate the browser zoom, it can really jack things up, but nothing to do about it. Then again I still run into people using IE6 so I guess things could always be worse. – user1289347 Apr 20 '12 at 02:21
  • @user1289247—I love it, and hate when it's disabled. To each their own. – RobG Apr 20 '12 at 04:27