-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.imgbox.min.js
9 lines (9 loc) · 2.52 KB
/
jquery.imgbox.min.js
1
2
3
4
5
6
7
8
9
/**
* jQuery imgbox 插件
* @author niqingyang
* @version 1.0
* @site:https://acme.top/
* @github https://github.com/acme-top/jquery.imgbox.js
* @date 2018-12-02
*/
!function(a){var b={zoom:true,drag:true,scale:1,};a.fn.imgbox=function(c){c=a.extend({},b,c);a(this).css({cursor:"zoom-in"}).parents("a").attr("href","javascript:void(0);").click(function(){return false}).css({cursor:"default",});a(this).click(function(){var f=a(this).attr("src");var k=a('<a target="_blank" class="check-original-image" href="'+f+'">查看原图</a>');var o=a('<div data-pop-layer="1" style=""></div>').css({position:"fixed",left:"0px",right:"0px",top:"0px",bottom:"0px",height:"100%",width:"100%",zIndex:"9999999",backgroundColor:"rgba(26,26,26,.65)",opacity:0.8,userSelect:"none"});var i=a('<img src="'+a(this).attr("src")+'" >').css({position:"fixed",top:"0px",zIndex:"10000000",display:"none"});var g=a(i).prop("width");var n=a(i).prop("height");var h=g/n;a("body").append(k).append(o).append(i).css({overflow:"hidden"});a(i).fadeIn("fast");a(k).click(function(){event.stopPropagation()});var m=function(){var p=g;var r=n;var s=a(window).width()-5;var q=a(window).height();p=p*c.scale<s?p*c.scale:s;r=p/h;if(r>q){r=q;p=r*h}a(i).width(p);a(i).height(r);a(i).css({left:(a(window).width()-p)/2+"px",top:(a(window).height()-r)/2+"px",})};var e=function(){a(window).off("resize",m).off("mousewheel",d).off("DOMMouseScroll",d);a(i).fadeOut("fast",function(){a(this).remove()});a("body").css({overflow:"auto"});a(k).remove();a(o).remove();if(c.drag){a(this).remove()}else{a(window).off("click",e)}return false};var d=function(p,r){var q=a(i).data("scale");if(!q){q=1}if(p.originalEvent.wheelDelta>0||p.originalEvent.detail<0){q+=0.1}else{q-=0.1;if(q<=0.01){return}}a(i).css({transform:"scale("+q+")"}).data("scale",q);return false};if(c.drag){var l=a('<a class="close-original-image material-icons" href="javascript:void(0);"></a>');a("body").append(l);a(i).css({cursor:"move",});function j(p){a(p).mousedown(function(t){var t=t||event;var r=t.clientX-this.offsetLeft;var q=t.clientY-this.offsetTop;if(p.setCapture){p.setCapture()}var s=function(v){var v=v||event;p.style.left=v.clientX-r+"px";p.style.top=v.clientY-q+"px"};var u=function(){a(document).off("mousemove",s).off("mouseup",u);if(p.releaseCapture){p.releaseCapture()}};a(document).on("mousemove",s);a(document).on("mouseup",u);return false})}j(i.get(0));a(l).click(e)}else{a(i).css({cursor:"zoom-out",});a(window).click(e)}a(window).on("resize",m).trigger("resize");if(c.zoom){a(window).on("mousewheel DOMMouseScroll",d)}})}}(jQuery);