-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.imgcentering.min.js
6 lines (6 loc) · 1.24 KB
/
jquery.imgcentering.min.js
1
2
3
4
5
6
/*!
* jquery.imgcentering.js v0.91 - jQuery plugin for Centering images and maximum sizing in block.
* Copyright (c) 2014 Lei Hau'oli Co.,Ltd. - https://github.com/leihauoli/jquery.imgcentering.js
* License: MIT
*/
;(function(b){var a=function(c){this.$win=$(window);this.$element=c;this.$image=this.$element.find("img");this.deferredCompleteImage=new $.Deferred();if(!this.$image.length){return}this.init()};a.prototype={init:function(){this.confirmCompleteImage();this.bindEvents()},bindEvents:function(){var c=this;this.$win.on("resize orientationchange",function(){c.adjustImageSizeAndPosition()});this.deferredCompleteImage.done(function(){c.adjustImageSizeAndPosition()})},confirmCompleteImage:function(){if(this.$image[0].complete){this.deferredCompleteImage.resolve();return}setTimeout($.proxy(function(){this.confirmCompleteImage()},this),100)},adjustImageSizeAndPosition:function(){var g=0,e=0,f=0,h=0,c=this.$element.width(),d=this.$element.height();this.$image.width("100%").height("auto");e=this.$image.height();if(e<d){this.$image.width("auto").height("100%")}g=this.$image.width();e=this.$image.height();f=(e-d)/2;h=(g-c)/2;this.$image.css({marginTop:-f,marginLeft:-h})}};$.fn.imgcentering=function(){return this.each(function(){new a($(this))})}})($);