/ Published in: JavaScript

I like how this site uses jQuery to center some elements and I wanted to save the code incase they change their site ever.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
jQuery.fn.centerx = function () { this.css("position","absolute"); this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px"); return this; } 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; } $(function(){ $("#header").centerx(); $("#dropzone, #browser").center(); }); $(window).resize(function(){ $("#header").centerx(); $("#dropzone, #browser").center(); });
URL: http://general-metrics.com/
Comments
