2017-02-16 10:44:43 +00:00
|
|
|
!function(a){var b={url:!1,callback:!1,target:!1,duration:120,on:"mouseover",touch:!0,onZoomIn:!1,onZoomOut:!1,magnify:1};a.zoom=function(b,c,d,e){var f,g,h,i,j,k,l,m=a(b),n=m.css("position"),o=a(c);return b.style.position=/(absolute|fixed)/.test(n)?n:"relative",b.style.overflow="hidden",d.style.width=d.style.height="",a(d).addClass("zoomImg").css({position:"absolute",top:0,left:0,opacity:0,width:d.width*e,height:d.height*e,border:"none",maxWidth:"none",maxHeight:"none"}).appendTo(b),{init:function(){g=m.outerWidth(),f=m.outerHeight(),c===b?(i=g,h=f):(i=o.outerWidth(),h=o.outerHeight()),j=(d.width-g)/i,k=(d.height-f)/h,l=o.offset()},move:function(a){var b=a.pageX-l.left,c=a.pageY-l.top;c=Math.max(Math.min(c,h),0),b=Math.max(Math.min(b,i),0),d.style.left=b*-j+"px",d.style.top=c*-k+"px"}}},a.fn.zoom=function(c){return this.each(function(){var d=a.extend({},b,c||{}),e=d.target&&a(d.target)[0]||this,f=this,g=a(f),h=document.createElement("img"),i=a(h),j="mousemove.zoom",k=!1,l=!1;if(!d.url){var m=f.querySelector("img");if(m&&(d.url=m.getAttribute("data-src")||m.currentSrc||m.src),!d.url)return}g.one("zoom.destroy",function(a,b){g.off(".zoom"),e.style.position=a,e.style.overflow=b,h.onload=null,i.remove()}.bind(this,e.style.position,e.style.overflow)),h.onload=function(){function b(b){m.init(),m.move(b),i.stop().fadeTo(a.support.opacity?d.duration:0,1,!!a.isFunction(d.onZoomIn)&&d.onZoomIn.call(h))}function c(){i.stop().fadeTo(d.duration,0,!!a.isFunction(d.onZoomOut)&&d.onZoomOut.call(h))}var m=a.zoom(e,f,h,d.magnify);"grab"===d.on?g.on("mousedown.zoom",function(d){1===d.which&&(a(document).one("mouseup.zoom",function(){c(),a(document).off(j,m.move)}),b(d),a(document).on(j,m.move),d.preventDefault())}):"click"===d.on?g.on("click.zoom",function(d){return k?void 0:(k=!0,b(d),a(document).on(j,m.move),a(document).one("click.zoom",function(){c(),k=!1,a(document).off(j,m.move)}),!1)}):"toggle"===d.on?g.on("click.zoom",function(a){k?c():b(a),k=!k}):"mouseover"===d.on&&(m.init(),g.on("mouseenter.zoom",b).on("mouseleave.zoom",c).on(j,m.move)),d.touch&&g.on("touchstart.zoom",function(a){a.preventDefault(),l?(l=!1,c()):(l=!0,b(a.originalEvent.touches[0]||a.originalEvent.changedTouches[0]))}).on("touchmove.zoom",function(a){a.preventDefault(),m.move(a.originalEvent.touches[0]||a.originalEvent.changedTouches[0])}).on("touchend.zoom",function(a){a.preventDefault(),l&&(l=!1,c())}),a.isFunction(d.callback)&&d.callback.call(h)},h.src=d.url})},a.fn.zoom.defaults=b}(window.jQuery);
|