Skip to content

Instantly share code, notes, and snippets.

@marcoris
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcoris/01eea9d2ae2594629977 to your computer and use it in GitHub Desktop.
Save marcoris/01eea9d2ae2594629977 to your computer and use it in GitHub Desktop.
rdSlider
$.fn.rdSlider=function(e){return this.each(function(){function t(){("left"==h.effect||"right"==h.effect)&&g.animate({"margin-left":m},500),("top"==h.effect||"bottom"==h.effect)&&g.animate({"margin-top":m},500)}function n(){b||(o.animate({width:"100%"},h.pause-h.animationSpeed,function(){a(),o.animate({width:"0"},h.animationSpeed)}),c=setInterval(function(){o.animate({width:"100%"},h.pause-h.animationSpeed,function(){a(),o.animate({width:"0"},h.animationSpeed)})},h.pause))}function a(){("left"==h.effect||"right"==h.effect)&&g.animate({"margin-left":r},h.animationSpeed,function(){s++,f(),l()}),("top"==h.effect||"bottom"==h.effect)&&g.animate({"margin-top":r},h.animationSpeed,function(){s++,f(),l()}),"fade"==h.effect&&(g.find("li:nth-child("+s+")").fadeOut(h.animationSpeed),s++,f(),l())}function f(){s==v.length&&"fade"!=h.effect&&(s=1,v.stop(),g.css(u,m)),s==v.length&&"fade"==h.effect&&(s=1,v.stop().fadeIn(h.animationSpeed))}function l(){$(".bullet").removeClass("bulletaktiv"),$(".bullet:nth-child("+s+")").addClass("bulletaktiv")}function d(){clearInterval(c),o.stop(),b&&(o.width(0),g.css("cursor","pointer"))}var o,c,h=$.extend({animationSpeed:1e3,pause:5e3,width:600,height:400,effect:"left",mouseenter:!0,bullets:!0,timeline:!0,timeline_height:3,timeline_color:"red",timeline_opacity:1},e),s=1,r="-=",m=0,u="margin-left",p=(h.pause+h.animationSpeed,$(this)),g=p.find("ul"),b=!1;h.animationSpeed>=h.pause&&alert("The animationSpeed can't be greater than or equal to pause!"),p.css({width:h.width,height:h.height,overflow:"hidden",position:"relative"}),p.find("ul").css({height:h.height,padding:0,margin:0}),p.find("ul li").css("list-style-type","none"),g.find("li:first-child").clone().insertAfter(g.find("li:last"));var v=g.find("li");if(h.bullets===!0){p.append('<div id="bullets"></div>');var w=$("#bullets");for(w.css("width",19*v.length),i=1;i<v.length;i++)w.append('<div class="bullet"></div>');$(".bullet").click(function(){var e=$(this).index();if(("left"==h.effect||"right"==h.effect||"linear"==h.effect)&&($(".linear").css("height",0),g.stop().animate({"margin-left":-e*h.width},500)),("top"==h.effect||"bottom"==h.effect)&&g.stop().animate({"margin-top":-e*h.height},500),"fade"==h.effect)for(i=0;i<=e;i++)e>i?g.find("li:nth-child("+(i+1)+")").fadeOut(500):g.find("li:nth-child("+(e+1)+")").fadeIn(500);b=!0,$(".bullet").removeClass("bulletaktiv"),$(this).addClass("bulletaktiv"),d()}),$(".bullet:first-child").addClass("bulletaktiv")}if(p.append('<div id="timeline"></div>'),o=$("#timeline"),o.css({height:h.timeline_height,background:h.timeline_color,opacity:h.timeline_opacity}),h.timeline===!1&&o.css("height",0),("left"==h.effect||"right"==h.effect)&&(g.css("width",v.length*h.width),v.css("float",h.effect)),("top"==h.effect||"bottom"==h.effect)&&(g.css("height",v.length*h.height),v.css("margin","0 0 -5px 0")),"fade"==h.effect){v.css({position:"absolute"});var S;for(i=1;i<=v.length;i++)S=1e3-i,g.find("li:nth-child("+i+")").css({"z-index":S})}"left"==h.effect&&(r+=h.width,n()),"right"==h.effect&&(r="+="+h.width,m="-"+(v.length*h.width-h.width),g.animate({"margin-left":m},0),n()),"top"==h.effect&&(r+=h.height,u="margin-top",n()),"bottom"==h.effect&&(r="+="+h.height,u="margin-top",m="-"+(v.length*h.height-h.height),g.animate({"margin-top":m},0),n()),"fade"==h.effect&&n(),h.mouseenter===!0&&g.on("mouseenter",d).on("mouseleave",n),g.click(function(){b&&(g.css("cursor","default"),$(".bullet").removeClass("bulletaktiv"),$(".bullet:first-child").addClass("bulletaktiv"),v.fadeIn(500),s=1,b=!1,t())})})};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment