Revision: 10288
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at December 16, 2008 08:05 by ginoplusio
Initial Code
var elt = $('ID_DIV_TO_CENTER'); // retrieve required dimensions var eltDims = elt.getDimensions(); var browserDims = document.body.getDimensions(); // calculate the center of the page using the browser and element dimensions var y = (browserDims.height - eltDims.height) / 2; var x = (browserDims.width - eltDims.width) / 2; // set the style of the element so it is centered var styles = { position : 'absolute', top : y + 'px', left : x + 'px' }; elt.setStyle(styles); elt.scrollTo();
Initial URL
http://www.barattalo.it/
Initial Description
Initial Title
javascript to center a div with prototype.js
Initial Tags
javascript, center
Initial Language
JavaScript