1/*! 2 * è½®æå¾ç»ä»¶js 3 * author: zhuyichao 4 * 2015.10 5 * v 1.1.4 6 * åªéç¨äºå¾çå忢æé®å¨ä¸ä¸ªdom容å¨å çï¼ 7 */ 8 9/* 10 * è½®æå¾ç»ä»¶ 11 */ 12$.fn.Xslider = function(options) { 13 var settings = { 14 // ææ æscrollx|scrolly|fade 15 affect: 'fade', 16 // å¨ç»é度 17 speed: 1200, 18 // æ¶é´é´é 19 space: 2000, 20 // èªå¨æ»å¨ 21 auto: true, 22 // 触åäºä»¶ 注æç¨mouseover代æ¿hover 23 trigger: 'mouseover', 24 // å 容容å¨idæclass 25 conbox: '.conbox', 26 // å 容æ ç¾ é»è®¤ä¸º<a> 27 ctag: '.ctag', 28 //说ææåç´æ¥ç¶å®¹å¨ï¼åºå®åºåï¼ä¸éå¾çååæ¶ä½¿ç¨ï¼ä¹å¯ä»¥ç´æ¥åå¨c-tagä¸åå¾çä¸èµ·ååï¼çå ·ä½éæ±ï¼ 29 titleBox: '.title-con', 30 // åæ¢è§¦åå¨idæclass 31 switcher: '.switcher', 32 // 忢卿 ç¾ é»è®¤ä¸ºa 33 stag: '.stag', 34 // å½å忢卿 ·å¼åç§° 35 current: 'cur', 36 // æ¯å¦éæºæå®é»è®¤å¹»ç¯å¾ç 37 rand: false, 38 // 容å¨å®½åº¦ 39 boxWidth: '100%', 40 boxHeight: '100%', 41 pre_b: '#left-btn', 42 43 next_b: '#right-btn' 44 }; 45 46 // settings = $.extend({}, settings, options); 47 $.extend(settings, options); 48 49 var $this = $(this), 50 index = 0, 51 last_index = 3, 52 $conbox = $this.find(settings.conbox), 53 $contents = $conbox.find(settings.ctag), 54 $switcher = $this.find(settings.switcher), 55 $stag = $switcher.find(settings.stag), 56 $titleCon = $this.find(settings.titleBox), 57 Timer; 58 59 60 61 $this.width(settings.boxWidth); 62 $contents.width($this.width()); 63 $this.width($this.width()); 64 if (settings.affect == 'scrollx') { 65 66 $contents.eq(0).clone().css('float', 'left').appendTo($conbox); 67 68 $conbox.width(($contents.length + 1) * $contents.width()); 69 70 $conbox.css('position', 'relative'); 71 $contents.css('float', 'left'); 72 } 73 74 if (settings.affect == 'scrolly') { 75 $contents.eq(0).clone().appendTo($conbox); 76 77 $conbox.height(($contents.length + 1) * $contents.height()); 78 79 $conbox.css('position', 'relative'); 80 $contents.css({ 81 display: 'block' 82 }); 83 } 84 85 var $newContents = $conbox.find(settings.ctag); 86 if (settings.boxWidth == "100%") { 87 88 $(window).on('resize', function(event) { 89 $this.width(settings.boxWidth); 90 $newContents.width($this.width()); 91 $conbox.width($newContents.length * $newContents.width()); 92 }); 93 94 } else { 95 96 $this.height(settings.boxHeight); 97 $contents.height(settings.boxHeight); 98 $newContents.find('img').height(settings.boxHeight); 99 } 100 101 102 103 // æ¸å模å¼é¢è®¾å¼ 104 if (settings.affect == 'fade') { 105 $switcher.css({ 106 'position': 'absolute', 107 'z-index': 10 108 }); 109 $.each($contents, function(k, v) { 110 if (k === 0) { 111 $(this).css({ 112 'position': 'absolute', 113 'z-index': 9 114 }) 115 } else { 116 $(this).css({ 117 'position': 'absolute', 118 'z-index': 1, 119 'opacity': 0 120 }); 121 } 122 }); 123 } 124 125 $this.css('overflow', 'hidden'); 126 127 128 129 // æ»å¨è½®æå¾æ¨¡å¼ 130 function slide(once) { 131 if (index > $contents.length) { 132 $conbox.css({ 133 'left': 0, 134 'top': 0 135 }) 136 index = 1; 137 } 138 if (index == $contents.length) { 139 $stag.removeClass(settings.current).eq(0).addClass(settings.current); 140 if (settings.affect == 'fade') { 141 index = 0; 142 } 143 } else { 144 $stag.removeClass(settings.current).eq(index).addClass(settings.current); 145 } 146 147 var title = $contents.eq(index).find('img').eq(0).attr('alt'); 148 $titleCon.html(title); 149 150 switch (settings.affect) { 151 // æ¨ªåæ»å¨ 152 case 'scrollx': 153 if (last_index == 0 && index == ($contents.length - 1)) { 154 $conbox.finish().css({ 155 'left': $contents.length * -$contents.width() 156 }); 157 } 158 if (index == $contents.length) { 159 $conbox.finish().animate({ 160 left: -$contents.width() * index 161 }, settings.speed, function() { 162 $conbox.css({ 163 'left': 0, 164 'top': 0 165 }); 166 }); 167 } else { 168 $conbox.finish().animate({ 169 left: -$contents.width() * index 170 }, settings.speed); 171 172 } 173 break; 174 // ç«çæ»å¨ 175 case 'scrolly': 176 if (last_index == 0 && index == ($contents.length - 1)) { 177 $conbox.css({ 178 'top': $contents.length * -$contents.height() 179 }); 180 } 181 if (index == $contents.length) { 182 $conbox.finish().animate({ 183 top: -$contents.height() * index 184 }, settings.speed, function() { 185 $conbox.css({ 186 'left': 0, 187 'top': 0 188 }); 189 }); 190 } else { 191 $conbox.finish().animate({ 192 top: -$contents.height() * index 193 }, settings.speed); 194 } 195 break; 196 // æ¸åæ¨¡å¼ 197 case 'fade': 198 $contents.eq(last_index).finish() 199 .animate({ 200 'opacity': 0 201 }, settings.speed / 2) 202 .css('z-index', 1) 203 .end().eq(index).css('z-index', 9).finish() 204 .animate({ 205 'opacity': 1 206 }, settings.speed / 2); 207 break; 208 case 'none': 209 $contents.hide().eq(index).show(); 210 break; 211 } 212 last_index = index; 213 if (last_index == $contents.length) { 214 last_index = 0; 215 } 216 index++; 217 218 // éæºåå¹»ï¼
219 if (settings.rand) { 220 index = Math.floor(Math.random() * $contents.length); 221 } 222 //夿æ¯å¦åªæ§è¡ä¸æ¬¡ã 223 if (once) { 224 //index = last_index; 225 } else { 226 clearTimeout(Timer); 227 Timer = setTimeout(slide, settings.space); 228 } 229 }; 230 231 232 // å¦æè®¾ç½®èªå¨ï¼å¼å§å¨ä½ 233 if (settings.auto) { 234 Timer = setTimeout(slide, settings.space); 235 } 236 237 // æ ç¾äºä»¶è§¦åæ¶ç«å³æ¾ç¤ºå½åå¾ç 238 $stag.on(settings.trigger, function() { 239 _pause(); 240 index = $(this).index(); 241 if (last_index == $contents.length - 1 && index == 0) { 242 index = $contents.length; 243 } 244 slide(true); 245 }); 246 247 // æ¬æµ®æ¶æåï¼ç¦»å¼æ¶ç»§ç» 248 $this.mouseenter(_pause); 249 $this.mouseleave(_continue); 250 // æåå¨ç»å¨ä½ 251 function _pause() { 252 if (Timer) { 253 clearTimeout(Timer); 254 } 255 }; 256 257 258 // ç»§ç»å¨ä½ 259 function _continue() { 260 261 if (Timer) { 262 clearTimeout(Timer); 263 } 264 if (settings.auto) { 265 Timer = setTimeout(slide, settings.space / 2); 266 } 267 }; 268 $(settings.next_b).click(function() { 269 $conbox.finish(); 270 clearTimeout(Timer); 271 index = last_index + 1; 272 slide(); 273 }); 274 $(settings.pre_b).click(function() { 275 $conbox.finish(); 276 clearTimeout(Timer); 277 index = last_index - 1; 278 if (index == -1) { 279 index = $contents.length - 1; 280 } 281 slide(); 282 }); 283 284 slide(true); //åå§åè½®æ 285}
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.