Skip to content

Instantly share code, notes, and snippets.

@ahmad24
Created December 7, 2013 14:10
Show Gist options
  • Save ahmad24/7842130 to your computer and use it in GitHub Desktop.
Save ahmad24/7842130 to your computer and use it in GitHub Desktop.
jQuery : scheleton plugin
(function($){
$.fn.center = function(){
var element = this;
$(element).load(function(){
changeCss();
$(window).bind("resize", function(){
changeCss();
});
function changeCss(){
var imageHeight = $(element).height();
var imageWidth = $(element).width();
var windowWidth = $(window).width();
var windowHeight = $(window).height();
$(element).css({
"position" : "absolute",
"left" : windowWidth / 2 - imageWidth / 2,
"top" : windowHeight /2 - imageHeight / 2
});
};
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment