-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.simslider.min.js
1 lines (1 loc) · 4.36 KB
/
jquery.simslider.min.js
1
(function(e){var t=function(t,r){this.$element=e(t);this.options=e.extend({},n,r,{});this.init()};t.prototype.init=function(){var t=this.options.start_index||0;this.is_animating=!1;this.is_playing=!1;this.slide_direction="right";this.$element.css({position:"relative",overflow:"hidden",width:this.options.width,height:this.options.height});this.$element.children().css({width:this.options.width,height:this.options.height});this.$element.wrap('<div class="simslider-wrapper">');this.$element.children().wrap('<div class="'+this.options.slide_class+'">');this.$element.children().css({display:"block",position:"absolute","z-index":0,top:0});e(this).data("current_slide_index",t);e(this).data("slides_count",this.$element.children().length);this._createNavigation();this._createPagination();this.setCurrentSlide(t);this.$element.children(":eq("+t+")").css({"z-index":2});this.$element.children(":not(:eq("+t+"))").hide();this.options.auto_play&&this.play()};t.prototype._createNavigation=function(){var t=this,n=this._createNavigationButton("Next","next"),r=this._createNavigationButton("Previous","previous"),i=this._createNavigationButton("Play","play"),s=this._createNavigationButton("Stop","stop");n.on("click",function(n){n.preventDefault();var r=e(t).data("current_slide_index")+1;t.slide_direction="right";t.goTo(r)});r.on("click",function(n){n.preventDefault();var r=e(t).data("current_slide_index")-1;t.slide_direction="left";t.goTo(r)});i.on("click",function(e){e.preventDefault();t.play()});s.on("click",function(e){e.preventDefault();t.stop()});this.$element.parent().append(e("<div>").addClass("simslider-pagination"))};t.prototype._createNavigationButton=function(t,n){return e("<a>").attr("href","#").addClass("simslider-navigation simslider-navigation-"+n).text(t).appendTo(this.$element.parent())};t.prototype._createPagination=function(){var t=this;this.$pagination=e("<div>").addClass("simslider-pagination").appendTo(this.$element.parent());var n=e("<ul>").appendTo(this.$pagination);for(var r=0;r<e(this).data("slides_count");r++){var i=e("<a>").attr("href","#"+r).html(r+1),s=e("<li>").append(i);n.append(s)}n.find("li a").on("click",function(n){n.preventDefault();t.stop();var r=e(this).parent().index();t.goTo(r);t.options.auto_play&&t.play()})};t.prototype.play=function(){var t=this;if(this.is_playing)return;this.is_playing=!0;this.slide_direction="right";e(this).data("playInterval",setInterval(function(){t._doPlay()},this.options.delay))};t.prototype.stop=function(){this.is_playing=!1;clearInterval(e(this).data("playInterval"));this._stopAnimation()};t.prototype._stopAnimation=function(){this.$element.children().clearQueue()};t.prototype.goTo=function(t){var n=e(this).data("current_slide_index"),r=e(this).data("slides_count");if(n==t||this.is_animating)return;t>=r&&(t=0);t<0&&(t=r-1);this.$element.children().finish();typeof this["_"+this.options.effect]=="function"?this["_"+this.options.effect](t):this._slide(t);e(this).data("current_slide_index",t)};t.prototype._doPlay=function(){var t=e(this).data("current_slide_index"),n=t+1;this.goTo(n)};t.prototype._fade=function(t){var n=this.$element,r=this;this.is_animating=!0;n.children(":eq("+t+")").css({"z-index":2,opacity:0,display:"block"}).animate({opacity:1},{duration:this.options.effect_delay,complete:function(){e(this).css({"z-index":2});r.is_animating=!1},queue:!1});n.children(":not(:eq("+t+"))").css({"z-index":0,opacity:1}).animate({opacity:0},{duration:this.options.effect_delay,complete:function(){e(this).hide()},queue:!1});this.setCurrentSlide(t)};t.prototype._slide=function(t){var n=this.$element,r=e(this).data("current_slide_index"),i=this,s=-this.options.width,o=this.options.width;if(this.slide_direction=="left"||r>t&&t>0){s=this.options.width;o=-this.options.width}this.is_animating=!0;n.children(":eq("+r+")").animate({left:s},1e3);n.children(":eq("+t+")").css({position:"absolute",top:0,"z-index":2,left:o}).show().animate({left:0},this.options.effect_delay,function(){n.children(":not(:eq("+t+"))").css({"z-index":0}).hide();i.is_animating=!1});this.setCurrentSlide(t)};t.prototype.setCurrentSlide=function(e){this.$pagination.find("li").removeClass("active");this.$pagination.find("li:eq("+e+")").addClass("active")};e.fn.simslider=function(n){return this.each(function(){e(this).data("Slider",new t(this,n))})};var n={width:600,height:300,delay:2e3,start_index:2,auto_play:!0,effect:"slide",effect_delay:1e3,slide_class:"simslider-slide"}})(jQuery);