I have made a jQuery plugin, but it doesn't work properly. The results are not consistent. Sometimes it does work, but sometimes not. I think the problem may be that some of the variables don't load fast enough.
Hope someone can help. Thanks in advance.
(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);
EDIT
The plugin is used for my image uploader. When I upload an image it should appear in a fancy way. I use this plugin for uploading: valums.com/ajax-upload and onComplete I use my plugin to show the image.