Share Coding

Tutorials, Problems, Stuffs …

How to make an Element to be Absolute Center on jQuery

In the previous tutorial that I have posted about Absolute Center on CSS:

However, it can be made by jQuery too. By using jQuery, it is easier to be used on any elements.

Click here for Demo

// Center Method
$ = function() {
	this.css('position', 'absolute');
	this.css('left', '50%');
	this.css('top', '50%');
	this.css('margin-left', -this.width() / 2 + 'px');
	this.css('margin-top', -this.height() / 2 + 'px');
	return this;

$(document).ready(function() {

    // Use it easily

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: