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:

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

{{ parent.tldr }}

{{ parent.urlSource.name }}