diff --git a/dist/js/swipr.js b/dist/js/swipr.js index 358a163..48c9edd 100644 --- a/dist/js/swipr.js +++ b/dist/js/swipr.js @@ -1 +1 @@ -!function(e,t){"function"==typeof define&&define.amd?define([],function(){return t(e)}):"object"==typeof exports?module.exports=t(e):e.swipr=t(e)}("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,function(c){"use strict";var d,u="querySelector"in document&&"addEventListener"in window&&"classList"in document.createElement("_"),v={wrapper:"[data-swipr-wrapper]",swiper:"[data-swipr]",swiprPreviousButtonClass:"swipr-prev",swiprPreviousButtonContent:"previous",swiprNextButtonClass:"swipr-next",swiprNextButtonContent:"next",disabledButtonClass:"is-disabled",amount:.8,speed:400,initiatedClass:"is-initiated",enabledClass:"is-enabled"};Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector),Element.prototype.closest||(Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector),Element.prototype.closest=function(e){var t=this;if(!document.documentElement.contains(this))return null;do{if(t.matches(e))return t;t=t.parentElement}while(null!==t);return null});var f=function(){var n={},s=!1,e=0;"[object Boolean]"===Object.prototype.toString.call(arguments[0])&&(s=arguments[0],e++);for(var t=function(e){for(var t in e)e.hasOwnProperty(t)&&(s&&"[object Object]"===Object.prototype.toString.call(e[t])?n[t]=f(n[t],e[t]):n[t]=e[t])};ee.clientWidth?(s.enable(e),t=e,0!=(n=d)&&(t.style.marginBottom=-2*n+"px",t.style.paddingBottom=n+"px"),o(e)):s.disable(e)})},Math.easeInOutQuad=function(e,t,n,s){return(e/=s/2)<1?n/2*e*e+t:-n/2*(--e*(e-2)-1)+t};var r=function(){var e=this.className;e==p.swiprPreviousButtonClass&&n(this.parentNode,"prev"),e==p.swiprNextButtonClass&&n(this.parentNode,"next")},a=function(){o(this)},l=function(){t||(t=setTimeout(function(){t=null,s.runswipr(e)},66))};return s.enable=function(e){var t;p&&(t=e,p&&(h(t).classList.contains(p.swiprPreviousButtonClass)&&h(t).removeAttribute("style"),b(t).classList.contains(p.swiprNextButtonClass)&&b(t).removeAttribute("style")),e.parentNode.classList.add(p.enabledClass),e.addEventListener("scroll",a,!1))},s.disable=function(e){p&&(i(e),e.parentNode.classList.remove(p.enabledClass),e.removeAttribute("style"))},s.destroy=function(){p&&(c.removeEventListener("resize",l,!1),function(e){if(p){var t=e.parentNode.getElementsByClassName(p.swiprPreviousButtonClass)[0],n=e.parentNode.getElementsByClassName(p.swiprNextButtonClass)[0];t.removeEventListener("click",r,!1),n.removeEventListener("click",r,!1),t.parentNode.removeChild(t),n.parentNode.removeChild(n)}}(m),m.parentNode.classList.remove(p.initiatedClass),m.parentNode.classList.remove(p.enabledClass),d=t=m=p=null)},s.init=function(e){var t;u&&("ontouchstart"in document.documentElement&&((t=navigator.userAgent).match(/Android/i)||t.match(/webOS/i)||t.match(/iPhone/i)||t.match(/iPod/i)||t.match(/iPad/i)||t.match(/Windows Phone/i)||t.match(/SymbianOS/i)||t.match(/RIM/i)||t.match(/BB/i))||(p=f(v,e||{}),d=function(){var e=document.createElement("div");e.style.visibility="hidden",e.style.width="100px",e.style.msOverflowStyle="scrollbar",document.body.appendChild(e);var t=e.offsetWidth;e.style.overflow="scroll";var n=document.createElement("div");n.style.width="100%",e.appendChild(n);var s=n.offsetWidth;return e.parentNode.removeChild(e),t!=s&&t-s}(),s.runswipr(e),c.addEventListener("resize",l,!1)))},s.init(e),s}}); \ No newline at end of file +!function(t,e){"function"==typeof define&&define.amd?define([],function(){return e(t)}):"object"==typeof exports?module.exports=e(t):t.swipr=e(t)}("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,function(p){"use strict";var m,f="querySelector"in document&&"addEventListener"in window&&"classList"in document.createElement("_"),v={wrapper:"[data-swipr-wrapper]",swiper:"[data-swipr]",startItem:"[data-swipr-start]",swiprPreviousButtonClass:"swipr-prev",swiprPreviousButtonContent:"previous",swiprNextButtonClass:"swipr-next",swiprNextButtonContent:"next",disabledButtonClass:"is-disabled",amount:.8,speed:400,initiatedClass:"is-initiated",enabledClass:"is-enabled"};Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector),Element.prototype.closest||(Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector),Element.prototype.closest=function(t){var e=this;if(!document.documentElement.contains(this))return null;do{if(e.matches(t))return e;e=e.parentElement}while(null!==e);return null});var h=function(){var n={},s=!1,t=0;"[object Boolean]"===Object.prototype.toString.call(arguments[0])&&(s=arguments[0],t++);for(var e=function(t){for(var e in t)t.hasOwnProperty(e)&&(s&&"[object Object]"===Object.prototype.toString.call(t[e])?n[e]=h(n[e],t[e]):n[e]=t[e])};tt.clientWidth?(a.enable(t),e=t,0!=(n=m)&&(e.style.marginBottom=-2*n+"px",e.style.paddingBottom=n+"px"),c(t)):a.disable(t)})},Math.easeInOutQuad=function(t,e,n,s){return(t/=s/2)<1?n/2*t*t+e:-n/2*(--t*(t-2)-1)+e};var u=function(){var t=this.className;t==o.swiprPreviousButtonClass&&n(this.parentNode,"prev"),t==o.swiprNextButtonClass&&n(this.parentNode,"next")},s=function(){c(this)},i=function(){e||(e=setTimeout(function(){e=null,a.runswipr(t)},66))};return a.enable=function(t){var e;o&&(e=t,o&&(b(e).classList.contains(o.swiprPreviousButtonClass)&&b(e).removeAttribute("style"),w(e).classList.contains(o.swiprNextButtonClass)&&w(e).removeAttribute("style")),t.parentNode.classList.add(o.enabledClass),t.addEventListener("scroll",s,!1))},a.disable=function(t){o&&(l(t),t.parentNode.classList.remove(o.enabledClass),t.removeAttribute("style"))},a.destroy=function(){o&&(p.removeEventListener("resize",i,!1),function(t){if(o){var e=t.parentNode.getElementsByClassName(o.swiprPreviousButtonClass)[0],n=t.parentNode.getElementsByClassName(o.swiprNextButtonClass)[0];e.removeEventListener("click",u,!1),n.removeEventListener("click",u,!1),e.parentNode.removeChild(e),n.parentNode.removeChild(n)}}(r),r.parentNode.classList.remove(o.initiatedClass),r.parentNode.classList.remove(o.enabledClass),m=e=r=o=null)},a.init=function(t){var e;f&&("ontouchstart"in document.documentElement&&((e=navigator.userAgent).match(/Android/i)||e.match(/webOS/i)||e.match(/iPhone/i)||e.match(/iPod/i)||e.match(/iPad/i)||e.match(/Windows Phone/i)||e.match(/SymbianOS/i)||e.match(/RIM/i)||e.match(/BB/i))||(o=h(v,t||{}),m=function(){var t=document.createElement("div");t.style.visibility="hidden",t.style.width="100px",t.style.msOverflowStyle="scrollbar",document.body.appendChild(t);var e=t.offsetWidth;t.style.overflow="scroll";var n=document.createElement("div");n.style.width="100%",t.appendChild(n);var s=n.offsetWidth;return t.parentNode.removeChild(t),e!=s&&e-s}(),a.runswipr(t),p.addEventListener("resize",i,!1)))},a.init(t),a}}); \ No newline at end of file diff --git a/index.html b/index.html index b27afc5..e97478e 100644 --- a/index.html +++ b/index.html @@ -42,6 +42,10 @@ padding-left: 80px; padding-right: 80px; } + + .is-active { + background: red; + } @@ -73,6 +77,17 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/package.json b/package.json index 2138d56..41fb142 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "swipr", "description": "Swipe through horizontal content. Buttons for non-mobile/non-touch devices. Natural swipe for mobile/touch devices", - "version": "1.0.1", + "version": "1.0.2", "homepage": "https://robinpoort.github.io/swipr/", "author": "https://github.com/robinpoort/swipr/graphs/contributors", "repository": { diff --git a/src/js/swipr.js b/src/js/swipr.js index da39362..f6ff322 100644 --- a/src/js/swipr.js +++ b/src/js/swipr.js @@ -27,6 +27,7 @@ var defaults = { wrapper: '[data-swipr-wrapper]', swiper: '[data-swipr]', + startItem: '[data-swipr-start]', swiprPreviousButtonClass: 'swipr-prev', swiprPreviousButtonContent: 'previous', swiprNextButtonClass: 'swipr-next', @@ -400,7 +401,13 @@ hideButtons($swiper); // Add initiated class - $swiper.parentNode.classList.add(settings.initiatedClass); + $swiper.parentNode.classList.add(localSettings.initiatedClass); + + // See if there's a start item + var startScroll = $swiper.querySelector(localSettings.startItem); + if (startScroll) { + animateScroll($swiper, startScroll.offsetLeft, settings.speed); + } // Check for scrollbar hasHorizontalScrollbar = $swiper.scrollWidth > $swiper.clientWidth;