1(function($){ 2 3 var fnName = 'magnifier'; 4 var magnifier = { 5 magnifier : ".magnifier",//æå¤å±çå¤§å®¹å¨ 6 7 container : ".magnifier-container",//éæ©å½å主å¾çæ¿è½½å®¹å¨ 8 9 containerImg : '.images-cover',//å¾ççå®¹å¨ 10 11 view : ".magnifier-view",//å¾çæ¾å¤§åæ¿è½½å®¹å¨ 12 13 width : 400,//å¾çæ¾å¤§åæ¿è½½å®¹å¨å®½åº¦ 14 15 height : 400,//å¾çæ¾å¤§åæ¿è½½å®¹å¨é«åº¦ 16 17 moveView : ".move-view",//è·éé¼ æ ç§»å¨çå®¹å¨ 18 19 moveWidth : null,//å¦æè®¾ç½®äºç§»å¨çåç宽度ï¼åä¸è®¡ç®ç¼©æ¾æ¯ä¾ 20 21 zoom : 4,//ç¼©æ¾æ¯ä¾ 22 23 thumbnail : ".magnifier-line > ul",//缩ç¥å¾å®¹å¨ 24 25 assembly : ".magnifier-btn",//æé®ç» 26 27 index : 0//å½åå¾ççç´¢å¼ 28 }; 29 30 31 window[fnName] = function(magnifierAttr){ 32 33 //è®¾ç½®å±æ§å¼ 34 if(typeof(magnifierAttr) == "object"){ 35 36 for( var n in magnifierAttr){ 37 38 magnifier[n] = magnifierAttr[n]; 39 } 40 } 41 42 var _this = this; 43 //ç»å®å®¹å¨ 44 _this.magnifier = $(magnifier.magnifier); 45 _this.container = _this.magnifier.find(magnifier.container); 46 _this.view = _this.magnifier.find(magnifier.view); 47 _this.moveView = _this.magnifier.find(magnifier.moveView); 48 _this.thumbnail = _this.magnifier.find(magnifier.thumbnail); 49 _this.assembly = _this.magnifier.find(magnifier.assembly); 50 _this.containerImg = _this.magnifier.find(magnifier.containerImg); 51 var imgBox = _this.containerImg; 52 53 //è¨ç½®å¯¬é« 54 _this.magnifier.css({ 55 "width" : magnifier.width 56 }); 57 _this.container.css({ 58 "width" : magnifier.width, 59 "height" : magnifier.height 60 }); 61 _this.view.css({ 62 "width" : magnifier.width, 63 "height" : magnifier.height 64 }); 65 66 var boxMoveViewWidth,boxMoveViewHeight; 67 if(magnifier.moveWidth){ 68 69 boxMoveViewWidth = magnifier.moveWidth; 70 }else{ 71 72 boxMoveViewWidth = magnifier.width/magnifier.zoom; 73 } 74 boxMoveViewHeight = boxMoveViewWidth; 75 76 _this.moveView.css({ 77 "width" : boxMoveViewWidth, 78 "height" : boxMoveViewHeight 79 }); 80 81 //计ç®ä½ç§¯ç¢°æçåé 82 var deviationXl, 83 deviationXr, 84 deviationYt, 85 deviationYb, 86 imgWidth, 87 imgHieght, 88 multiple; 89 90 _this.eqImg = function(){ 91 92 var img = new Image(), 93 src = _this.thumbnail.find("img").eq(magnifier.index).attr('src'); 94 95 img.src = src; 96 97 //æ¿è½½å®¹å¨çå®½é« 98 containerWidth = magnifier.width; 99 containerHeight = magnifier.height; 100 101 _this.thumbnail.find('>*').removeClass('active').eq(magnifier.index).addClass('active'); 102 103 function imgLoadEnd(){ 104 105 if(img.width == 0){ 106 107 img.onload = imgLoadEnd; 108 } 109 110 var styleCss; 111 if(img.width > img.height){ 112 113 imgWidth = magnifier.width; 114 imgHieght = img.height / (img.width / magnifier.width); 115 styleCss = "top:50%;margin-top:"+(-imgHieght/2)+"px"; 116 }else{ 117 118 imgWidth = img.width / (img.height / magnifier.width); 119 imgHieght = magnifier.width; 120 121 styleCss = "left:50%;margin-left:"+(-imgWidth/2)+"px"; 122 } 123 124 imgBox.empty().append('<img src="'+src+'" width="'+imgWidth+'" height="'+imgHieght+'" style="'+styleCss+'" />'); 125 126 //éæ°è®¡ç®ç§»å¨çåä¸å¾ççåæ° 127 multiple = magnifier.width / boxMoveViewWidth; 128 129 //容å¨å è½½å¾ç 130 _this.view.empty().append('<img src="'+src+'" width="'+imgWidth*multiple+'" height="'+imgHieght*multiple+'" />'); 131 132 //åç§»é 133 deviationXl = (magnifier.width - imgWidth) /2; 134 deviationXr = magnifier.width - deviationXl - boxMoveViewWidth + 1;//è¿éé¢å¤+1çæ¯è¦è®¡ç®å®¹å¨çå·¦è¾¹æ¡ 135 deviationYt = (magnifier.height - imgHieght) /2; 136 deviationYb = magnifier.height - deviationYt - boxMoveViewHeight + 1;//è¿éé¢å¤+1çæ¯è¦è®¡ç®å®¹å¨çä¸è¾¹æ¡ 137 138 } 139 140 imgLoadEnd(); 141 } 142 //å®æåæ§è¡ 143 _this.eqImg(); 144 145 _this.moveFn = function(e){ 146 147 var X = (e.clientX-_this.magnifier.offset().left)-boxMoveViewWidth/2, 148 Y = (e.clientY-_this.magnifier.offset().top + $(document).scrollTop())-boxMoveViewHeight/2; 149 150 endX = (X > deviationXl) ? (X < deviationXr) ? X : deviationXr : deviationXl; 151 endY = (Y > deviationYt) ? (Y < deviationYb) ? Y : deviationYb : deviationYt; 152 153 //å½Yè½´è¶ åºå®¹å¨ 154 endY = (endY > 0) ? (endY > (magnifier.width-boxMoveViewHeight)) ? (magnifier.height-boxMoveViewHeight) : endY : 0; 155 _this.moveView.css({ 156 'left' : endX, 157 'top' : endY, 158 'display' : "block" 159 }); 160 161 positionX = (endX - (magnifier.width-imgWidth)/2)*multiple; 162 positionY = (endY - (magnifier.height-imgHieght)/2)*multiple; 163 164 _this.view.css({ 165 'display' : "block" 166 }).find('img').css({ 167 'margin-left' : -positionX, 168 'margin-top' : -positionY 169 }); 170 } 171 172 _this.container.on('mousemove',function(e){
173 174 _this.moveFn(e); 175 176 }).on('mouseleave',function(){ 177 178 _this.moveView.hide(); 179 _this.view.hide(); 180 }); 181 182 var thumbnailImg = _this.thumbnail.find('>*'), 183 lineLenght = thumbnailImg.length; 184 _this.imgMove = function(_boole){ 185 186 (_boole) ? magnifier.index++ : magnifier.index--; 187 188 var _deviation = Math.ceil(magnifier.width / thumbnailImg.width() /2); 189 if(lineLenght < _deviation){ 190 return false; 191 } 192 193 (magnifier.index < 0) ? magnifier.index = 0 : (magnifier.index > lineLenght-_deviation) ? magnifier.index = lineLenght - _deviation : magnifier.index; 194 195 var endLeft = (thumbnailImg.width() * magnifier.index) - thumbnailImg.width(); 196 197 _this.thumbnail.css({ 198 199 "left" : ((endLeft > 0) ? -endLeft : 0)+"px" 200 }); 201 } 202 203 //æé®ç»å¨ä½ 204 _this.assembly.find(">*").on('click',function(){ 205 206 _this.imgMove($(this).index()); 207 }); 208 209 thumbnailImg.on('click',function(){ 210 211 magnifier.index = $(this).index(); 212 213 //æ¾ç¤ºå¾ç 214 _this.eqImg(); 215 216 //缩ç¥å¾ä½ç½®ç§»å¨ 217 _this.imgMove(magnifier.index); 218 }); 219 220 _this.setIndex = function(n){ 221 222 magnifier.index = (n) ? n : 0; 223 } 224 225 return _this; 226 } 227})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.