Over a million developers have joined DZone.

Page Zoom With Javascript

·

var size = 1;
var factor = 0.95;
var lo = 0.5;
var hi = 1.7;
function sizechange() {
  var body = document.getElementsByTagName('body')[0];
  if (size <= lo) {
     factor = 1.05;
  }
  if (size >= hi) {
     factor = 0.95;
  }
  size = size * factor;
  body.style.fontSize = '' + size + 'em';
  setTimeout('sizechange()', 100);
}
window.onload = sizechange;
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}