Return to Snippet

Revision: 52779
at November 1, 2011 15:08 by jackkeller


Initial Code
$(document).ready(function() {
  jQuery.fn.center = function () {
	  this.css("position","absolute");
	  this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
	  this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
	  return this;
  }
  $("#id").center();
});

Initial URL


Initial Description


Initial Title
Center an element on the screen

Initial Tags
jquery

Initial Language
JavaScript