1/** 2 * jCarouselLite - jQuery plugin to navigate images/any content in a carousel style widget. 3 * @requires jQuery v1.2 or above 4 * 5 * http://gmarwaha.com/jquery/jcarousellite/ 6 * 7 * Copyright (c) 2007 Ganeshji Marwaha (gmarwaha.com) 8 * Dual licensed under the MIT and GPL licenses: 9 * http://www.opensource.org/licenses/mit-license.php 10 * http://www.gnu.org/licenses/gpl.html 11 * 12 * Version: 1.0.1 13 * Note: Requires jquery 1.2 or above from version 1.0.1 14 */ 15/** 16btnPrev : ÉÏÒ»ÕŰ´Å¥ 17btnNext : ÏÂÒ»ÕŰ´Å¥ 18btnGo : ±êÇ©¿ØÖÆ£¬Ò²¾ÍÊÇÓá¯1,2,3,4¡¡¯À´¿ØÖÆ 19mouseWheel : ÊÇ·ñÖ§³ÖÊó±ê»¬ÂÖ¹ö¶¯£¬ÊôÐÔÖµ£ºfalse / true£»Ä¬ÈÏΪfalse ´ò¿ª´ËÏîÐèÒªjQuery UI²å¼þÖ§³Ö 20auto : ÉèÖÃ×Ô¶¯²¥·ÅµÄËÙ¶È£¬Ä¬ÈÏ×Ô¶¯²¥·ÅÊǹرյ쬏ñʽ auto: 800 (Ϊ²¥·ÅËÙ¶È) 21speed : ¶¯»Ð§¹ûËÙ¶È 22easing : ¶¯»Ð§¹ûÓÅ»¯£¬¹ÃÇÒÕâôÀïÃæ ÐèÒªÍⲿ²å¼þÖ§³Ö 23vertical : ¶¯»·½Ïò£¬Èç¹ûÉèÖÃΪtrue£¬Ôò±íʾ´¹Ö±¹ö¶¯£¬Ä¬ÈÏΪfalse 24circular : ÊÇ·ñÖØ¸´²¥·Å£¬Èç¹ûÉèÖÃΪfalse£¬Ôòµ½×îºóÒ»¸öÏÂÒ»ÕŰ´Å¥¾Íµã²»¶¯ÁË£¬µ½µÚÒ»ÕÅÉÏÒ»ÕŰ´Å¥¾Íµã²»¶¯ 25visible : ÉèÖÃĬÈÏÏÔʾ¼¸¸öli£¬Ä¬ÈÏÊÇ3¸ö 26start : Ч¹û´ÓµÚ¼¸¸ö¿ªÊ¼£¬Ä¬ÈÏΪ0 27scroll : Ò»´Î»¬¶¯¼¸¸öli£¬Ä¬ÈÏÊÇ2 28beforeStart : Õâ¸öÊǽӿڣ¬Ã¿´Î»¬¶¯Ð§¹ûÖ´ÐÐ֮ǰִÐеÄ×Ô¶¨Ò庯Êý 29afterEnd : Õâ¸öÊǽӿڣ¬Ã¿´Î»¬¶¯Ð§¹ûÖ´ÐÐÖ®ºóÖ´ÐеÄ×Ô¶¨Ò庯Êý 30 */ 31 32/** 33 * Creates a carousel-style navigation widget for images/any-content from a simple HTML markup. 34 * 35 * The HTML markup that is used to build the carousel can be as simple as... 36 * 37 * <div class="carousel"> 38 * <ul> 39 * <li><img src="?js/image/1.jpg" alt="1"></li> 40 * <li><img src="?js/image/2.jpg" alt="2"></li> 41 * <li><img src="?js/image/3.jpg" alt="3"></li> 42 * </ul> 43 * </div> 44 * 45 * As you can see, this snippet is nothing but a simple div containing an unordered list of images. 46 * You don't need any special "class" attribute, or a special "css" file for this plugin. 47 * I am using a class attribute just for the sake of explanation here. 48 * 49 * To navigate the elements of the carousel, you need some kind of navigation buttons. 50 * For example, you will need a "previous" button to go backward, and a "next" button to go forward. 51 * This need not be part of the carousel "div" itself. It can be any element in your page. 52 * Lets assume that the following elements in your document can be used as next, and prev buttons... 53 * 54 * <button class="prev"><<</button> 55 * <button class="next">>></button> 56 * 57 * Now, all you need to do is call the carousel component on the div element that represents it, and pass in the 58 * navigation buttons as options. 59 * 60 * $(".carousel").jCarouselLite({ 61 * btnNext: ".next", 62 * btnPrev: ".prev" 63 * }); 64 * 65 * That's it, you would have now converted your raw div, into a magnificient carousel. 66 * 67 * There are quite a few other options that you can use to customize it though. 68 * Each will be explained with an example below. 69 * 70 * @param an options object - You can specify all the options shown below as an options object param. 71 * 72 * @option btnPrev, btnNext : string - no defaults 73 * @example 74 * $(".carousel").jCarouselLite({ 75 * btnNext: ".next", 76 * btnPrev: ".prev" 77 * }); 78 * @desc Creates a basic carousel. Clicking "btnPrev" navigates backwards and "btnNext" navigates forward. 79 * 80 * @option btnGo - array - no defaults 81 * @example 82 * $(".carousel").jCarouselLite({ 83 * btnNext: ".next", 84 * btnPrev: ".prev", 85 * btnGo: [".0", ".1", ".2"] 86 * }); 87 * @desc If you don't want next and previous buttons for navigation, instead you prefer custom navigation based on 88 * the item number within the carousel, you can use this option. Just supply an array of selectors for each element 89 * in the carousel. The index of the array represents the index of the element. What i mean is, if the 90 * first element in the array is ".0", it means that when the element represented by ".0" is clicked, the carousel 91 * will slide to the first element and so on and so forth. This feature is very powerful. For example, i made a tabbed 92 * interface out of it by making my navigation elements styled like tabs in css. As the carousel is capable of holding 93 * any content, not just images, you can have a very simple tabbed navigation in minutes without using any other plugin. 94 * The best part is that, the tab will "slide" based on the provided effect. :-) 95 * 96 * @option mouseWheel : boolean - default is false 97 * @example 98 * $(".carousel").jCarouselLite({ 99 * mouseWheel: true 100 * }); 101 * @desc The carousel can also be navigated using the mouse wheel interface of a scroll mouse instead of using buttons. 102 * To get this feature working, you have to do 2 things. First, you have to include the mouse-wheel plugin from brandon. 103 * Second, you will have to set the option "mouseWheel" to true. That's it, now you will be able to navigate your carousel 104 * using the mouse wheel. Using buttons and mouseWheel or not mutually exclusive. You can still have buttons for navigation 105 * as well. They complement each other. To use both together, just supply the options required for both as shown below. 106 * @example 107 * $(".carousel").jCarouselLite({ 108 * btnNext: ".next", 109 * btnPrev: ".prev", 110 * mouseWheel: true 111 * }); 112 * 113 * @option auto : number - default is null, meaning autoscroll is disabled by default 114 * @example 115 * $(".carousel").jCarouselLite({ 116 * auto: 800, 117 * speed: 500 118 * }); 119 * @desc You can make your carousel auto-navigate itself by specfying a millisecond value in this option. 120 * The value you specify is the amount of time between 2 slides. The default is null, and that disables auto scrolling. 121 * Specify this value and magically your carousel will start auto scrolling. 122 * 123 * @option speed : number - 200 is default 124 * @example 125 * $(".carousel").jCarouselLite({ 126 * btnNext: ".next", 127 * btnPrev: ".prev",
128 * speed: 800 129 * }); 130 * @desc Specifying a speed will slow-down or speed-up the sliding speed of your carousel. Try it out with 131 * different speeds like 800, 600, 1500 etc. Providing 0, will remove the slide effect. 132 * 133 * @option easing : string - no easing effects by default. 134 * @example 135 * $(".carousel").jCarouselLite({ 136 * btnNext: ".next", 137 * btnPrev: ".prev", 138 * easing: "bounceout" 139 * }); 140 * @desc You can specify any easing effect. Note: You need easing plugin for that. Once specified, 141 * the carousel will slide based on the provided easing effect. 142 * 143 * @option vertical : boolean - default is false 144 * @example 145 * $(".carousel").jCarouselLite({ 146 * btnNext: ".next", 147 * btnPrev: ".prev", 148 * vertical: true 149 * }); 150 * @desc Determines the direction of the carousel. true, means the carousel will display vertically. The next and 151 * prev buttons will slide the items vertically as well. The default is false, which means that the carousel will 152 * display horizontally. The next and prev items will slide the items from left-right in this case. 153 * 154 * @option circular : boolean - default is true 155 * @example 156 * $(".carousel").jCarouselLite({ 157 * btnNext: ".next", 158 * btnPrev: ".prev", 159 * circular: false 160 * }); 161 * @desc Setting it to true enables circular navigation. This means, if you click "next" after you reach the last 162 * element, you will automatically slide to the first element and vice versa. If you set circular to false, then 163 * if you click on the "next" button after you reach the last element, you will stay in the last element itself 164 * and similarly for "previous" button and first element. 165 * 166 * @option visible : number - default is 3 167 * @example 168 * $(".carousel").jCarouselLite({ 169 * btnNext: ".next", 170 * btnPrev: ".prev", 171 * visible: 4 172 * }); 173 * @desc This specifies the number of items visible at all times within the carousel. The default is 3. 174 * You are even free to experiment with real numbers. Eg: "3.5" will have 3 items fully visible and the 175 * last item half visible. This gives you the effect of showing the user that there are more images to the right. 176 * 177 * @option start : number - default is 0 178 * @example 179 * $(".carousel").jCarouselLite({ 180 * btnNext: ".next", 181 * btnPrev: ".prev", 182 * start: 2 183 * }); 184 * @desc You can specify from which item the carousel should start. Remember, the first item in the carousel 185 * has a start of 0, and so on. 186 * 187 * @option scrool : number - default is 1 188 * @example 189 * $(".carousel").jCarouselLite({ 190 * btnNext: ".next", 191 * btnPrev: ".prev", 192 * scroll: 2 193 * }); 194 * @desc The number of items that should scroll/slide when you click the next/prev navigation buttons. By 195 * default, only one item is scrolled, but you may set it to any number. Eg: setting it to "2" will scroll 196 * 2 items when you click the next or previous buttons. 197 *
198 * @option beforeStart, afterEnd : function - callbacks 199 * @example 200 * $(".carousel").jCarouselLite({ 201 * btnNext: ".next", 202 * btnPrev: ".prev", 203 * beforeStart: function(a) { 204 * alert("Before animation starts:" + a); 205 * }, 206 * afterEnd: function(a) { 207 * alert("After animation ends:" + a); 208 * } 209 * }); 210 * @desc If you wanted to do some logic in your page before the slide starts and after the slide ends, you can 211 * register these 2 callbacks. The functions will be passed an argument that represents an array of elements that 212 * are visible at the time of callback. 213 * 214 * 215 * @cat Plugins/Image Gallery 216 * @author Ganeshji Marwaha/[email protected] 217 */ 218 219(function($) { // Compliant with jquery.noConflict() 220$.fn.jCarouselLite = function(o) { 221 o = $.extend({ 222 btnPrev: null, 223 btnNext: null, 224 btnGo: null, 225 mouseWheel: false, 226 auto: null, 227onMouse: false, 228 speed: 200, 229 easing: null, 230 231 vertical: false, 232 circular: true, 233 visible: 3, 234 start: 0, 235 scroll: 1, 236 237 beforeStart: null, 238 afterEnd: null 239 }, o || {}); 240 241 return this.each(function() { // Returns the element collection. Chainable. 242 243 var running = false, animCss=o.vertical?"top":"left", sizeCss=o.vertical?"height":"width"; 244 var div = $(this), ul = $("ul", div), tLi = $("li", ul), tl = tLi.size(), v = o.visible; 245 246 if(o.circular) { 247 ul.prepend(tLi.slice(tl-v-1+1).clone()) 248 .append(tLi.slice(0,v).clone()); 249 o.start += v; 250 } 251var TimeID = 0; 252 var li = $("li", ul), itemLength = li.size(), curr = o.start; 253 div.css("visibility", "visible"); 254 255 li.css({overflow: "hidden", float: o.vertical ? "none" : "left"}); 256 ul.css({margin: "0", padding: "0", position: "relative", "list-style-type": "none", "z-index": "1"}); 257 div.css({overflow: "hidden", position: "relative", "z-index": "2", left: "0px"}); 258 259 var liSize = o.vertical ? height(li) : width(li); // Full li size(incl margin)-Used for animation 260 var ulSize = liSize * itemLength; // size of full ul(total length, not just for the visible items) 261 var divSize = liSize * v; // size of entire div(total length for just the visible items) 262 263 li.css({width: li.width(), height: li.height()}); 264 ul.css(sizeCss, ulSize+"px").css(animCss, -(curr*liSize)); 265 266 div.css(sizeCss, divSize+"px");
266 // Width of the DIV. length of visible images 267 268 if(o.btnPrev) 269 $(o.btnPrev).click(function() { 270 return go(curr-o.scroll); 271 }); 272 273 if(o.btnNext) 274 $(o.btnNext).click(function() { 275 return go(curr+o.scroll); 276 }); 277 278 if(o.btnGo) 279 $.each(o.btnGo, function(i, val) { 280 $(val).click(function() { 281 return go(o.circular ? o.visible+i : i); 282 }); 283 }); 284 285 if(o.mouseWheel && div.mousewheel) 286 div.mousewheel(function(e, d) { 287 return d>0 ? go(curr-o.scroll) : go(curr+o.scroll); 288 }); 289 290 if(o.auto) 291 TimeID = setInterval(function() { 292 go(curr+o.scroll); 293 }, o.auto+o.speed); 294 295 if (o.onMouse) 296 tLi.bind("mouseover", function() { if (o.auto) { 297 clearInterval(TimeID); 298 go(curr + o.scroll); // ÕâÀï×îºÃ×¢Ê͵ô£¬»áÓ°ÏìÐüͣЧ¹û 299 } }) 300 //mouseout 301 tLi.bind("mouseout", function() { if (o.auto) { TimeID = setInterval(function() { go(curr + o.scroll); }, o.auto + o.speed); } }) 302 303 function vis() { 304 return li.slice(curr).slice(0,v); 305 }; 306 307 function go(to) { 308 if(!running) { 309 310 if(o.beforeStart) 311 o.beforeStart.call(this, vis()); 312 313 if(o.circular) { // If circular we are in first or last, then goto the other end 314 if(to<=o.start-v-1) { // If first, then goto last 315 ul.css(animCss, -((itemLength-(v*2))*liSize)+"px"); 316 // If "scroll" > 1, then the "to" might not be equal to the condition; it can be lesser depending on the number of elements. 317 curr = to==o.start-v-1 ? itemLength-(v*2)-1 : itemLength-(v*2)-o.scroll; 318 } else if(to>=itemLength-v+1) { // If last, then goto first 319 ul.css(animCss, -( (v) * liSize ) + "px" ); 320 // If "scroll" > 1, then the "to" might not be equal to the condition; it can be greater depending on the number of elements. 321 curr = to==itemLength-v+1 ? v+1 : v+o.scroll; 322 } else curr = to; 323 } else { // If non-circular and to points to first or last, we just return. 324 if(to<0 || to>itemLength-v) return; 325 else curr = to; 326 } // If neither overrides it, the curr will still be "to" and we can proceed. 327 328 running = true; 329 330 ul.animate( 331 animCss == "left" ? { left: -(curr*liSize) } : { top: -(curr*liSize) } , o.speed, o.easing, 332 function() { 333 if(o.afterEnd) 334 o.afterEnd.call(this, vis()); 335 running = false; 336 } 337 ); 338 // Disable buttons when the carousel reaches the last/first, and enable when not 339 if(!o.circular) { 340 $(o.btnPrev + "," + o.btnNext).removeClass("disabled"); 341 $( (curr-o.scroll<0 && o.btnPrev) 342 || 343 (curr+o.scroll > itemLength-v && o.btnNext) 344 || 345 [] 346 ).addClass("disabled"); 347 } 348 349 } 350 return false; 351 }; 352 }); 353}; 354 355function css(el, prop) { 356 return parseInt($.css(el[0], prop)) || 0; 357}; 358function width(el) { 359 return el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight'); 360}; 361function height(el) { 362 return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom'); 363}; 364 365})(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.