(function($) { $.fn.showhide = function(options) { var defaults = { appear: true, speed: 500 }, settings = $.extend({}, defaults, options); this.each(function() { var $this = $(this), elementWidth = $this.width(), elementHeight = $this.height(), newWidth = 0, newHeight = 0, marginX = Math.floor(elementWidth / 2), marginY = Math.floor(elementHeight/ 2); if(settings.appear) { console.log(elementWidth + ' ' + elementHeight + ' ' + marginX + ' ' + marginY); $this.css({ width: newWidth + 'px', height: newHeight + 'px', margin: marginY + 'px ' + marginX + 'px' }); $this.animate({ width: elementWidth + 'px', height: elementHeight + 'px', margin: '0px', opacity: 'show' }, settings.speed); } else { } }); return this; } })(jQuery);