Posted By

wesleymacente on 11/22/10


Tagged

div jquery center with


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

icebob
AllKnightAccess
baires
johnw
dubogii
banjomamo


CENTER DIV WITH JQUERY


 / Published in: jQuery
 

  1. jQuery.fn.center = function () {
  2. this.css("position","absolute");
  3. this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
  4. this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
  5. return this;
  6. }
  7.  
  8.  
  9. $(element).center();

Report this snippet  

You need to login to post a comment.