Skip to content

Instantly share code, notes, and snippets.

View bgkittrell's full-sized avatar

Ben Kittrell bgkittrell

View GitHub Profile
@bgkittrell
bgkittrell / center-prototype.js
Created October 17, 2010 02:26
Center Horizontal and Vertically using Prototype
Element.addMethods({
centerHorizontally: function(element) {
if (!(element = $(element))) return;
var vpWidth = $(document).viewport.getWidth();
var width = element.getWidth();
element.style.left = (vpWidth / 2) - (width / 2) + 'px';
return element;
},