1/** 2 * my-image-carousel.js 3 * 4 * è½»éå¾çè½®æç»ä»¶ 5 * 6 * ä½¿ç¨æ¹å¼ï¼ 7 * ImageCarousel.init('carousel-image', [ 8 * '/static/image/a.jpg', 9 * '/static/image/b.jpg', 10 * '/static/image/c.jpg' 11 * ], 3000); 12 * 13 * // è¿å timerIdï¼å¯ç¨ clearInterval 忢 14 * 15 * åæ°ï¼ 16 * @param {string} imgId - <img> å ç´ ç id 17 * @param {string[]} images - å¾ç URL æ°ç»ï¼è³å° 1 å¼ ï¼ 18 * @param {number} interval - 忢é´éï¼æ¯«ç§ï¼ï¼é»è®¤ 3000 19 */ 20 21(function () { 22 'use strict'; 23 24 window.ImageCarousel = { 25 26 /** 27 * åå§åè½®æ 28 * @param {string} imgId - img æ ç¾ç id 29 * @param {string[]} images - å¾çè·¯å¾æ°ç» 30 * @param {number} interval - è½®æé´éï¼æ¯«ç§ï¼ï¼é»è®¤ 3000 31 * @returns {number} setInterval ç IDï¼å¯ç¨äº clearInterval 忢 32 */ 33 init: function (imgId, images, interval) { 34 if (!imgId || !images || images.length === 0) { 35 console.warn('[ImageCarousel] åæ°æ æï¼è·³è¿åå§å'); 36 return null; 37 } 38 39 interval = interval || 3000; 40 41 // å¦æåªæä¸å¼ å¾ï¼ä¸éè¦è½®æ 42 if (images.length === 1) return null; 43 44 var currentIndex = 0; 45 var imgEl = document.getElementById(imgId); 46 47 if (!imgEl) { 48 console.warn('[ImageCarousel] æªæ¾å°å ç´ : #' + imgId); 49 return null; 50 } 51 52 var timerId = setInterval(function () { 53 currentIndex = (currentIndex + 1) % images.length; 54 imgEl.src = images[currentIndex]; 55 }, interval); 56 57 console.log('[ImageCarousel] åå§å宿: #' + imgId + ', ' + images.length + 'å¼ , é´é' + interval + 'ms'); 58 return timerId; 59 } 60 }; 61 62})();
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.