From df0a531ccc6584e0177f5ec47afc95613d3e0241 Mon Sep 17 00:00:00 2001 From: Nick Piscitelli Date: Sat, 10 Nov 2018 21:03:31 -0500 Subject: [PATCH] Fix slideToScroll `auto` bug and update documentation --- docs/assets/js/glider.js | 8 ++++---- docs/index.html | 4 +++- glider.js | 8 ++++---- glider.min.js | 4 ++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/docs/assets/js/glider.js b/docs/assets/js/glider.js index b54540d..5ed2b9d 100644 --- a/docs/assets/js/glider.js +++ b/docs/assets/js/glider.js @@ -88,10 +88,10 @@ if (!paging) paging = breakpointChanged; if (_.opt.slidesToShow === 'auto'){ - _.opt.slidesToShow = Math.floor(_.containerWidth / _.opt.itemWidth) - if (_.opt.slidesToScroll === 'auto'){ - _.opt.slidesToScroll = _.opt.slidesToShow; - } + _.opt.slidesToShow = Math.floor(_.containerWidth / _.opt.itemWidth); + } + if (_.opt.slidesToScroll === 'auto'){ + _.opt.slidesToScroll = _.opt.slidesToShow; } _.itemWidth = _.containerWidth / _.opt.slidesToShow; diff --git a/docs/index.html b/docs/index.html index f3f5b2f..a3e950c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -832,9 +832,11 @@

Settings

  • slidesToScroll
    - Type: number
    + Type: number | string
    Default: 1
    The number of slides to scroll when arrow navigation is used
    + + If this value is set to auto, it will match the value of `slidesToScroll`.
  • itemWidth
    diff --git a/glider.js b/glider.js index b54540d..5ed2b9d 100644 --- a/glider.js +++ b/glider.js @@ -88,10 +88,10 @@ if (!paging) paging = breakpointChanged; if (_.opt.slidesToShow === 'auto'){ - _.opt.slidesToShow = Math.floor(_.containerWidth / _.opt.itemWidth) - if (_.opt.slidesToScroll === 'auto'){ - _.opt.slidesToScroll = _.opt.slidesToShow; - } + _.opt.slidesToShow = Math.floor(_.containerWidth / _.opt.itemWidth); + } + if (_.opt.slidesToScroll === 'auto'){ + _.opt.slidesToScroll = _.opt.slidesToShow; } _.itemWidth = _.containerWidth / _.opt.slidesToShow; diff --git a/glider.min.js b/glider.min.js index 65a0212..f5bab1c 100644 --- a/glider.min.js +++ b/glider.min.js @@ -14,8 +14,8 @@ */ (function(){var e=window.Glider=function(){return function(b,a){this.ele=b;this.ele._glider=this;this["default"]={slidesToScroll:1,slidesToShow:1,duration:.5,easing:function(a,b,e,g,f){return g*(b/=f)*b+e}};this.opt=Object.assign({},this["default"],a);this.aIndex=this.page=this.slide=0;this.arrows={};this._opt=this.opt;this.track=document.createElement("div");this.track.className="glider-track";for(this.ele.appendChild(this.track);1!==this.ele.children.length;)this.track.appendChild(this.ele.children[0]); -this.init();this.ele.addEventListener("scroll",this.updateControls.bind(this));window.addEventListener("resize",this.init.bind(this,!0))}}();e.prototype.init=function(b,a){var c=this,d=0;c.slides=c.track.children;[].forEach.call(c.slides,function(a){a.classList.add("glider-slide")});c.containerWidth=c.ele.clientWidth;c.opt=c._opt;var e=c.settingsBreakpoint();a||(a=e);"auto"===c.opt.slidesToShow&&(c.opt.slidesToShow=Math.floor(c.containerWidth/c.opt.itemWidth),"auto"===c.opt.slidesToScroll&&(c.opt.slidesToScroll= -c.opt.slidesToShow));c.itemWidth=c.containerWidth/c.opt.slidesToShow;[].forEach.call(c.slides,function(a){a.style.height="auto";a.style.width=c.itemWidth+"px";d+=c.itemWidth});c.track.style.width=d+"px";c.trackWidth=d;if(!b||a)c.bindArrows(),c.buildDots(),c.updateControls();c.event(b?"refresh ":"loaded")};e.prototype.buildDots=function(){if(this.opt.dots){if(this.dots="string"===typeof this.opt.dots?document.querySelector(this.opt.dots):this.opt.dots){this.dots.innerHTML="";this.dots.className="glider-dots"; +this.init();this.ele.addEventListener("scroll",this.updateControls.bind(this));window.addEventListener("resize",this.init.bind(this,!0))}}();e.prototype.init=function(b,a){var c=this,d=0;c.slides=c.track.children;[].forEach.call(c.slides,function(a){a.classList.add("glider-slide")});c.containerWidth=c.ele.clientWidth;c.opt=c._opt;var e=c.settingsBreakpoint();a||(a=e);"auto"===c.opt.slidesToShow&&(c.opt.slidesToShow=Math.floor(c.containerWidth/c.opt.itemWidth));"auto"===c.opt.slidesToScroll&&(c.opt.slidesToScroll= +c.opt.slidesToShow);c.itemWidth=c.containerWidth/c.opt.slidesToShow;[].forEach.call(c.slides,function(a){a.style.height="auto";a.style.width=c.itemWidth+"px";d+=c.itemWidth});c.track.style.width=d+"px";c.trackWidth=d;if(!b||a)c.bindArrows(),c.buildDots(),c.updateControls();c.event(b?"refresh ":"loaded")};e.prototype.buildDots=function(){if(this.opt.dots){if(this.dots="string"===typeof this.opt.dots?document.querySelector(this.opt.dots):this.opt.dots){this.dots.innerHTML="";this.dots.className="glider-dots"; for(var b=0;b=a.trackWidth;a.arrows.prev&&a.arrows.prev.classList.toggle("disabled",0>=a.ele.scrollLeft||c);a.arrows.next&&a.arrows.next.classList.toggle("disabled",a.ele.scrollLeft+a.containerWidth>=Math.floor(a.trackWidth)||c);a.slide=Math.round(a.ele.scrollLeft/a.itemWidth); a.page=Math.round(a.ele.scrollLeft/a.containerWidth);[].forEach.call(a.slides,function(b,c){var d=b.classList,e=d.contains("visible"),l=a.ele.scrollLeft,m=a.ele.scrollLeft+a.containerWidth,k=a.itemWidth*c,n=k+a.itemWidth;d.toggle("active",a.slide===c);k>=l&&n<=m?e||(a.event("slide-visible",{slide:c}),d.add("visible")):e&&(a.event("slide-visible",{slide:c}),d.remove("visible"))});a.dots&&[].forEach.call(a.dots.children,function(b,c){b.classList.toggle("active",a.page===c)});b&&a.opt.scrollLock&&(clearTimeout(a.scrollLock),