Center an Element

jQuery.fn.centerElement = 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; } $('#item').centerElement();
A function to place an element in the center of the page.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.