Advertisement
Neolot

jCarouselLite 1.0.1 modified

Feb 7th, 2012
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 4.23 KB | None | 0 0
  1. /*
  2. jCarouselLite 1.0.1
  3. Modified by Neolot
  4. http://neolot.com
  5. */
  6. (function($) {
  7.     $.fn.jCarouselLite = function(o) {
  8.         o = $.extend({btnPrev:null,btnNext:null,btnGo:null,mouseWheel:false,auto:null,speed:200,easing:null,vertical:false,circular:true,visible:3,start:0,scroll:1,beforeStart:null,afterEnd:null}, o || {});
  9.         return this.each(function() {
  10.             var b = false,animCss = o.vertical ? "top" : "left",sizeCss = o.vertical ? "height" : "width";
  11.             var c = $(this),ul = $("ul", c),tLi = $("li", ul),tl = tLi.size(),v = o.visible;
  12.             if ( $("li", ul).size() <= o.visible ) {
  13.                 o.circular = false;
  14.             }
  15.             $("li", ul).each(function(i) {
  16.                 var it = i + 1;
  17.                 $(this).find('a').attr('rev', 'item' + it);
  18.             });
  19.  
  20.             if (o.circular) {
  21.                 ul.prepend(tLi.slice(tl - v - 1 + 1).clone()).append(tLi.slice(0, v).clone());
  22.                 o.start += v
  23.             }
  24.             var f = $("li", ul),itemLength = f.size(),curr = o.start;
  25.             c.css("visibility", "visible");
  26.             f.css({overflow:"hidden",float:o.vertical ? "none" : "left"});
  27.             ul.css({margin:"0",padding:"0",position:"relative","list-style-type":"none","z-index":"1"});
  28.             c.css({overflow:"hidden",position:"relative","z-index":"2",left:"0px"});
  29.             var g = o.vertical ? height(f) : width(f);
  30.             var h = g * itemLength;
  31.             var j = g * v;
  32.             f.css({width:f.width(),height:f.height(equalHeight(f))});
  33.             ul.css(sizeCss, h + "px").css(animCss, -(curr * g));
  34.             c.css(sizeCss, j + "px");
  35.             if (o.btnPrev)$(o.btnPrev).click(function() {return go(curr - o.scroll)});
  36.             if (o.btnNext)$(o.btnNext).click(function() {return go(curr + o.scroll)});
  37.             if (o.btnGo)$.each(o.btnGo, function(i, a) {$(a).click(function() {return go(o.circular ? o.visible + i : i)})});
  38.             if (o.mouseWheel && c.mousewheel)c.mousewheel(function(e, d) {return d > 0 ? go(curr - o.scroll) : go(curr + o.scroll)});
  39.             if (o.auto)setInterval(function() {go(curr + o.scroll)}, o.auto + o.speed);
  40.             function vis() {return f.slice(curr).slice(0, v)}
  41.  
  42.             ;
  43.             function go(a) {
  44.                 if (!b) {
  45.                     if (o.beforeStart)o.beforeStart.call(this, vis());
  46.                     if (o.circular) {
  47.                         if (a <= o.start - v - 1) {
  48.                             ul.css(animCss, -((itemLength - (v * 2)) * g) + "px");
  49.                             curr = a == o.start - v - 1 ? itemLength - (v * 2) - 1 : itemLength - (v * 2) - o.scroll
  50.                         } else if (a >= itemLength - v + 1) {
  51.                             ul.css(animCss, -((v) * g) + "px");
  52.                             curr = a == itemLength - v + 1 ? v + 1 : v + o.scroll
  53.                         } else curr = a
  54.                     } else {if (a < 0 || a > itemLength - v)return; else curr = a}
  55.                     b = true;
  56.                     ul.animate(animCss == "left" ? {left:-(curr * g)} : {top:-(curr * g)}, o.speed, o.easing, function() {
  57.                         if (o.afterEnd)o.afterEnd.call(this, vis());
  58.                         b = false
  59.                     });
  60.                     if (!o.circular) {
  61.                         $(o.btnPrev + "," + o.btnNext).removeClass("disabled");
  62.                         $((curr - o.scroll < 0 && o.btnPrev) || (curr + o.scroll > itemLength - v && o.btnNext) || []).addClass("disabled")
  63.                     }
  64.                 }
  65.                 return false
  66.             }
  67.         })
  68.     };
  69.     function css(a, b) {return parseInt($.css(a[0], b)) || 0}
  70.  
  71.     ;
  72.     function width(a) {return a[0].offsetWidth + css(a, 'marginLeft') + css(a, 'marginRight')}
  73.  
  74.     ;
  75.     function height(a) {return a[0].offsetHeight + css(a, 'marginTop') + css(a, 'marginBottom')}
  76.     function equalHeight(a){
  77.         var tallest = 0;
  78.         if ( a.size() > 1 ) {
  79.             a.each(function(){
  80.                 var height = $(this).height();
  81.                 if (tallest < height) tallest = height;
  82.             });
  83.         } else {
  84.             tallest = a.height();
  85.         }
  86.         return tallest;
  87.     }
  88. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement