From f470f72ef2fd4f0945b43b068621ed1f7cb58d88 Mon Sep 17 00:00:00 2001 From: Gabor Lenard Date: Sun, 23 Oct 2016 11:07:13 +0200 Subject: [PATCH] v3.2.3 Fixes zenscroll.moving() not returning true when scroll is in progress --- package.json | 2 +- zenscroll-min.js | 2 +- zenscroll.js | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index b8b474d..d7a0c3f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zenscroll", - "version": "3.2.2", + "version": "3.2.3", "description": "A module to smooth-scroll web pages and containers (DIVs)", "main": "zenscroll.js", "files": ["zenscroll.js", "zenscroll-min.js"], diff --git a/zenscroll-min.js b/zenscroll-min.js index e9a4ee9..0204e8f 100644 --- a/zenscroll-min.js +++ b/zenscroll-min.js @@ -1 +1 @@ -!function(t,e){"function"==typeof define&&define.amd?define([],e()):"object"==typeof module&&module.exports?module.exports=e():t.zenscroll=e()}(this,function(){"use strict";if("undefined"==typeof window||!("document"in window))return{};var t=function(t,e,n){e=e||999,n||0===n||(n=9);var o,i=document.documentElement,r=function(){return"getComputedStyle"in window&&"smooth"===window.getComputedStyle(t?t:document.body)["scroll-behavior"]},c=function(){return t?t.scrollTop:window.scrollY||i.scrollTop},u=function(){return t?Math.min(t.offsetHeight,window.innerHeight):window.innerHeight||i.clientHeight},f=function(e){return t?e.offsetTop:e.getBoundingClientRect().top+c()-i.offsetTop},l=function(){clearTimeout(o),o=0},a=function(n,f,a){if(l(),r())(t||window).scrollTo(0,n),a&&a();else{var d=c(),s=Math.max(n,0)-d;f=f||Math.min(Math.abs(s),e);var m=(new Date).getTime();!function e(){o=setTimeout(function(){var n=Math.min(((new Date).getTime()-m)/f,1),o=Math.max(Math.floor(d+s*(n<.5?2*n*n:n*(4-2*n)-1)),0);t?t.scrollTop=o:window.scrollTo(0,o),n<1&&u()+o<(t||i).scrollHeight?e():(setTimeout(l,99),a&&a())},9)}()}},d=function(t,e,o){a(f(t)-n,e,o)},s=function(t,e,o){var i=t.getBoundingClientRect().height,r=f(t),l=r+i,s=u(),m=c(),h=m+s;r-ns?d(t,e,o):l+n>h?a(l-s+n,e,o):o&&o()},m=function(t,e,n,o){a(Math.max(f(t)-u()/2+(n||t.getBoundingClientRect().height/2),0),e,o)},h=function(t,o){t&&(e=t),(0===o||o)&&(n=o)};return{setup:h,to:d,toY:a,intoView:s,center:m,stop:l,moving:function(){return!!o}}},e=t();if("addEventListener"in window&&"smooth"!==document.body.style.scrollBehavior&&!window.noZensmooth){var n=function(t){try{history.replaceState({},"",window.location.href.split("#")[0]+t)}catch(t){}};window.addEventListener("click",function(t){for(var o=t.target;o&&"A"!==o.tagName;)o=o.parentNode;if(!(!o||1!==t.which||t.shiftKey||t.metaKey||t.ctrlKey||t.altKey)){var i=o.getAttribute("href")||"";if(0===i.indexOf("#"))if("#"===i)t.preventDefault(),e.toY(0),n("");else{var r=o.hash.substring(1),c=document.getElementById(r);c&&(t.preventDefault(),e.to(c),n("#"+r))}}},!1)}return{createScroller:t,setup:e.setup,to:e.to,toY:e.toY,intoView:e.intoView,center:e.center,stop:e.stop,moving:e.moving}}); \ No newline at end of file +!function(t,e){"function"==typeof define&&define.amd?define([],e()):"object"==typeof module&&module.exports?module.exports=e():t.zenscroll=e()}(this,function(){"use strict";if("undefined"==typeof window||!("document"in window))return{};var t=function(t,e,n){e=e||999,n||0===n||(n=9);var o,i=function(t){o=t},r=document.documentElement,c=function(){return"getComputedStyle"in window&&"smooth"===window.getComputedStyle(t?t:document.body)["scroll-behavior"]},u=function(){return t?t.scrollTop:window.scrollY||r.scrollTop},f=function(){return t?Math.min(t.offsetHeight,window.innerHeight):window.innerHeight||r.clientHeight},l=function(e){return t?e.offsetTop:e.getBoundingClientRect().top+u()-r.offsetTop},a=function(){clearTimeout(o),i(0)},d=function(n,o,l){if(a(),c())(t||window).scrollTo(0,n),l&&l();else{var d=u(),s=Math.max(n,0)-d;o=o||Math.min(Math.abs(s),e);var m=(new Date).getTime();!function e(){i(setTimeout(function(){var n=Math.min(((new Date).getTime()-m)/o,1),i=Math.max(Math.floor(d+s*(n<.5?2*n*n:n*(4-2*n)-1)),0);t?t.scrollTop=i:window.scrollTo(0,i),n<1&&f()+i<(t||r).scrollHeight?e():(setTimeout(a,99),l&&l())},9))}()}},s=function(t,e,o){d(l(t)-n,e,o)},m=function(t,e,o){var i=t.getBoundingClientRect().height,r=l(t),c=r+i,a=f(),m=u(),h=m+a;r-na?s(t,e,o):c+n>h?d(c-a+n,e,o):o&&o()},h=function(t,e,n,o){d(Math.max(l(t)-f()/2+(n||t.getBoundingClientRect().height/2),0),e,o)},w=function(t,o){t&&(e=t),(0===o||o)&&(n=o)};return{setup:w,to:s,toY:d,intoView:m,center:h,stop:a,moving:function(){return!!o}}},e=t();if("addEventListener"in window&&"smooth"!==document.body.style.scrollBehavior&&!window.noZensmooth){var n=function(t){try{history.replaceState({},"",window.location.href.split("#")[0]+t)}catch(t){}};window.addEventListener("click",function(t){for(var o=t.target;o&&"A"!==o.tagName;)o=o.parentNode;if(!(!o||1!==t.which||t.shiftKey||t.metaKey||t.ctrlKey||t.altKey)){var i=o.getAttribute("href")||"";if(0===i.indexOf("#"))if("#"===i)t.preventDefault(),e.toY(0),n("");else{var r=o.hash.substring(1),c=document.getElementById(r);c&&(t.preventDefault(),e.to(c),n("#"+r))}}},!1)}return{createScroller:t,setup:e.setup,to:e.to,toY:e.toY,intoView:e.intoView,center:e.center,stop:e.stop,moving:e.moving}}); \ No newline at end of file diff --git a/zenscroll.js b/zenscroll.js index 33f198f..1fc9006 100644 --- a/zenscroll.js +++ b/zenscroll.js @@ -1,5 +1,5 @@ /** - * Zenscroll 3.2.2 + * Zenscroll 3.2.3 * https://github.com/zengabor/zenscroll/ * * Copyright 2015–2016 Gabor Lenard @@ -61,6 +61,9 @@ } var scrollTimeoutId + var setScrollTimeoutId = function (newValue) { + scrollTimeoutId = newValue + } var docElem = document.documentElement // Detect if the browser already supports native smooth scrolling (e.g., Firefox 36+ and Chrome 49+) and it is enabled: @@ -98,7 +101,7 @@ */ var stopScroll = function () { clearTimeout(scrollTimeoutId) - scrollTimeoutId = 0 + setScrollTimeoutId(0) } /** @@ -122,7 +125,7 @@ duration = duration || Math.min(Math.abs(distance), defaultDuration) var startTime = new Date().getTime(); (function loopScroll() { - scrollTimeoutId = setTimeout(function () { + setScrollTimeoutId(setTimeout(function () { var p = Math.min((new Date().getTime() - startTime) / duration, 1) // percentage var y = Math.max(Math.floor(startY + distance*(p < 0.5 ? 2*p*p : p*(4 - p*2)-1)), 0) if (scrollContainer) { @@ -138,7 +141,7 @@ onDone() } } - }, 9) + }, 9)) })() } }