sweet-scroll
Advanced tools
Comparing version 0.7.1 to 1.0.0
{ | ||
"name": "sweet-scroll", | ||
"version": "0.7.1", | ||
"version": "1.0.0", | ||
"description": "Modern and the sweet smooth scroll library.", | ||
"main": "sweet-scroll.js", | ||
"scripts": { | ||
"start": "gulp start", | ||
"test": "gulp test", | ||
"build": "gulp build", | ||
"lint": "gulp lint" | ||
"start": "npm run watch & npm run demo", | ||
"test": "npm run lint && npm run karma", | ||
"build": "npm run build:js && npm run demo:build", | ||
"build:js": "NODE_ENV=production rollup -i src/sweet-scroll.js -o sweet-scroll.js -c && uglifyjs --compress --mangle -o sweet-scroll.min.js --comments -- sweet-scroll.js", | ||
"watch": "npm run watch:js & npm run watch:test", | ||
"watch:js": "onchange 'src/**/*.js' -- npm run build:js", | ||
"watch:test": "onchange 'test/**/*.js' -- npm run karma", | ||
"lint": "npm run eslint", | ||
"karma": "NODE_ENV=test karma start karma.conf.js --single-run", | ||
"eslint": "eslint src/**/*.js test/**/*.js .eslintrc.js --no-ignore", | ||
"demo": "npm run demo:server & npm run demo:watch:js & npm run demo:watch:sass", | ||
"demo:server": "browser-sync start -s 'demo/' -f 'demo/**/*' --no-notify --no-open --no-ghost-mode", | ||
"demo:build": "npm run demo:build:js && npm run demo:build:sass", | ||
"demo:build:js": "copyfiles sweet-scroll.js demo/js/", | ||
"demo:build:sass": "node-sass demo/sass/ -o demo/css/ --output-style compressed && postcss --use autoprefixer demo/css/*.css -d demo/css/", | ||
"demo:watch:js": "onchange 'sweet-scroll.js' -- npm run demo:build:js", | ||
"demo:watch:sass": "onchange 'demo/sass/**/*.scss' -- npm run demo:build:sass" | ||
}, | ||
@@ -32,34 +45,32 @@ "files": [ | ||
"devDependencies": { | ||
"babel-eslint": "^6.0.3", | ||
"autoprefixer": "^6.3.6", | ||
"babel-eslint": "^6.0.4", | ||
"babel-plugin-espower": "^2.1.2", | ||
"babel-preset-es2015": "^6.6.0", | ||
"babel-preset-es2015": "^6.9.0", | ||
"babel-preset-es2015-rollup": "^1.1.1", | ||
"babel-preset-stage-0": "^6.5.0", | ||
"babelify": "^7.2.0", | ||
"browser-sync": "^2.12.3", | ||
"browserify": "^13.0.0", | ||
"gulp": "^3.9.1", | ||
"gulp-autoprefixer": "^3.1.0", | ||
"gulp-eslint": "^2.0.0", | ||
"gulp-load-plugins": "^1.2.2", | ||
"gulp-plumber": "^1.1.0", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-rollup": "^1.8.0", | ||
"gulp-sass": "^2.3.1", | ||
"gulp-uglify": "^1.5.3", | ||
"babelify": "^7.3.0", | ||
"browser-sync": "^2.12.8", | ||
"browserify": "^13.0.1", | ||
"copyfiles": "^0.2.1", | ||
"eslint": "^2.10.2", | ||
"karma": "^0.13.22", | ||
"karma-browserify": "^5.0.4", | ||
"karma-browserify": "^5.0.5", | ||
"karma-cli": "^1.0.0", | ||
"karma-fixture": "^0.2.6", | ||
"karma-html2js-preprocessor": "^0.1.0", | ||
"karma-mocha": "^0.2.2", | ||
"karma-html2js-preprocessor": "^1.0.0", | ||
"karma-mocha": "^1.0.1", | ||
"karma-phantomjs-launcher": "^1.0.0", | ||
"karma-phantomjs-shim": "^1.3.0", | ||
"karma-phantomjs-shim": "^1.4.0", | ||
"mocha": "^2.4.5", | ||
"node-sass": "^3.7.0", | ||
"onchange": "^2.4.0", | ||
"phantomjs-prebuilt": "^2.1.7", | ||
"power-assert": "^1.3.1", | ||
"rollup": "^0.26.0", | ||
"postcss-cli": "^2.5.2", | ||
"power-assert": "^1.4.1", | ||
"rollup": "^0.26.3", | ||
"rollup-plugin-babel": "^2.4.0", | ||
"run-sequence": "^1.1.5", | ||
"uglify-js": "^2.6.2", | ||
"watchify": "^3.7.0" | ||
} | ||
} |
@@ -100,3 +100,3 @@ sweet-scroll.js | ||
completeScroll: null, | ||
stepScroll: null, | ||
stepScroll: null | ||
} | ||
@@ -126,3 +126,3 @@ ``` | ||
- `easeInQuint` | ||
- `easeOutQuint` (default) | ||
- `easeOutQuint` **(default)** | ||
- `easeInOutQuint` | ||
@@ -235,2 +235,3 @@ * **Sine** | ||
// In initial scroll will update the hash without leaving a history. | ||
// Support for IE10+. | ||
sweetScroll.to(hash, {updateURL: "replace"}); | ||
@@ -249,17 +250,17 @@ } | ||
* `new SweetScroll(options = {}, container = "body, html")` | ||
* `to(distance, options = {})` | ||
* `toTop(distance, options = {})` | ||
* `toLeft(distance, options = {})` | ||
* `toElement($el, options = {})` | ||
* `update(options = {})` | ||
* `stop(gotoEnd = false)` | ||
* `destroy()` | ||
* **Callbacks** | ||
- `initialized: function(){}` | ||
- `beforeScroll: function(toScroll, trigger){}` | ||
- `cancelScroll: function(){}` | ||
- `afterScroll: function(toScroll, trigger){}` | ||
- `completeScroll: function(isCancel){}` | ||
- `stepScroll: function(currentTime, props){}` | ||
* [new SweetScroll(options = {}, container = "body, html")](#new-sweetscrolloptions---container--body-html) | ||
* [to(distance, options = {})](#todistance-options--) | ||
* [toTop(distance, options = {})](#totopdistance-options--) | ||
* [toLeft(distance, options = {})](#toleftdistance-options--) | ||
* [toElement(el, options = {})](#toelementel-options--) | ||
* [update(options = {})](#updateoptions--) | ||
* [stop(gotoEnd = false)](#stopgotoend--true) | ||
* [destroy()](#destroy) | ||
* [Callbacks](#callbacks) | ||
- `initialized() {}` | ||
- `beforeScroll(toScroll, trigger) {}` | ||
- `cancelScroll() {}` | ||
- `afterScroll(toScroll, trigger) {}` | ||
- `completeScroll(isCancel) {}` | ||
- `stepScroll(currentTime, props) {}` | ||
@@ -353,5 +354,5 @@ `distance` to can specify the CSS Selector or scroll position. | ||
### toElement($el, options = {}) | ||
### toElement(el, options = {}) | ||
**$el: {Element}** | ||
**el: {Element}** | ||
**options: {Object}** | ||
@@ -387,3 +388,3 @@ | ||
**gotoEnd: {boolean}** | ||
**gotoEnd: {Boolean}** | ||
@@ -390,0 +391,0 @@ Will stop the current scroll animation. |
/*! | ||
* sweet-scroll | ||
* Modern and the sweet smooth scroll library. | ||
* | ||
* @author tsuyoshiwada | ||
* @homepage https://github.com/tsuyoshiwada/sweet-scroll | ||
* @license MIT | ||
* @version 0.7.1 | ||
* @version 1.0.0 | ||
*/ | ||
(function (global, factory) { | ||
@@ -49,3 +48,14 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1; | ||
var cos = Math.cos; | ||
var sin = Math.sin; | ||
var pow = Math.pow; | ||
var abs = Math.abs; | ||
var sqrt = Math.sqrt; | ||
var asin = Math.asin; | ||
var PI = Math.PI; | ||
var max = Math.max; | ||
var min = Math.min; | ||
var round = Math.round; | ||
var MAX_ARRAY_INDEX = pow(2, 53) - 1; | ||
var classTypeList = ["Boolean", "Number", "String", "Function", "Array", "Object"]; | ||
@@ -60,20 +70,8 @@ var classTypes = {}; | ||
if (obj == null) { | ||
return obj + ""; | ||
return ""; | ||
} | ||
return (typeof obj === "undefined" ? "undefined" : babelHelpers.typeof(obj)) === "object" || typeof obj === "function" ? classTypes[Object.prototype.toString.call(obj)] || "object" : typeof obj === "undefined" ? "undefined" : babelHelpers.typeof(obj); | ||
} | ||
function isArray(obj) { | ||
return Array.isArray(obj); | ||
} | ||
function isArrayLike(obj) { | ||
var length = obj == null ? null : obj.length; | ||
return isNumber(length) && length >= 0 && length <= MAX_ARRAY_INDEX; | ||
} | ||
function isObject(obj) { | ||
return !isArray(obj) && getType(obj) === "object"; | ||
} | ||
function isNumber(obj) { | ||
@@ -91,2 +89,12 @@ return getType(obj) === "number"; | ||
function isArray(obj) { | ||
return Array.isArray(obj); | ||
} | ||
function isArrayLike(obj) { | ||
var length = obj == null ? null : obj.length; | ||
return isNumber(length) && length >= 0 && length <= MAX_ARRAY_INDEX; | ||
} | ||
function isNumeric(obj) { | ||
@@ -96,2 +104,6 @@ return !isArray(obj) && obj - parseFloat(obj) + 1 >= 0; | ||
function isObject(obj) { | ||
return !isArray(obj) && getType(obj) === "object"; | ||
} | ||
function hasProp(obj, key) { | ||
@@ -101,19 +113,6 @@ return obj && obj.hasOwnProperty(key); | ||
function merge(obj) { | ||
for (var _len = arguments.length, sources = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
sources[_key - 1] = arguments[_key]; | ||
} | ||
each(sources, function (source) { | ||
each(source, function (value, key) { | ||
obj[key] = value; | ||
}); | ||
}); | ||
return obj; | ||
} | ||
function each(obj, iterate, context) { | ||
if (obj == null) return obj; | ||
context = context || obj; | ||
var ctx = context || obj; | ||
@@ -123,9 +122,7 @@ if (isObject(obj)) { | ||
if (!hasProp(obj, key)) continue; | ||
if (iterate.call(context, obj[key], key) === false) break; | ||
if (iterate.call(ctx, obj[key], key) === false) break; | ||
} | ||
} else if (isArrayLike(obj)) { | ||
var i = void 0, | ||
length = obj.length; | ||
for (i = 0; i < length; i++) { | ||
if (iterate.call(context, obj[i], i) === false) break; | ||
for (var i = 0; i < obj.length; i++) { | ||
if (iterate.call(ctx, obj[i], i) === false) break; | ||
} | ||
@@ -137,2 +134,16 @@ } | ||
function merge(obj) { | ||
for (var _len = arguments.length, sources = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
sources[_key - 1] = arguments[_key]; | ||
} | ||
each(sources, function (source) { | ||
each(source, function (value, key) { | ||
obj[key] = value; | ||
}); | ||
}); | ||
return obj; | ||
} | ||
function removeSpaces(str) { | ||
@@ -142,2 +153,5 @@ return str.replace(/\s*/g, "") || ""; | ||
var win = window; | ||
var doc = document; | ||
function $(selector) { | ||
@@ -147,3 +161,4 @@ var context = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; | ||
if (!selector) return; | ||
return (context == null ? document : context).querySelector(selector); | ||
return (context == null ? doc : context).querySelector(selector); | ||
} | ||
@@ -155,9 +170,11 @@ | ||
if (!selector) return; | ||
return (context == null ? document : context).querySelectorAll(selector); | ||
return (context == null ? doc : context).querySelectorAll(selector); | ||
} | ||
function matches(el, selector) { | ||
var matches = (el.document || el.ownerDocument).querySelectorAll(selector); | ||
var i = matches.length; | ||
while (--i >= 0 && matches.item(i) !== el) {} | ||
var results = (el.document || el.ownerDocument).querySelectorAll(selector); | ||
var i = results.length; | ||
while (--i >= 0 && results.item(i) !== el) {} | ||
return i > -1; | ||
@@ -177,3 +194,2 @@ } | ||
function isRootContainer(el) { | ||
var doc = document; | ||
return el === doc.documentElement || el === doc.body; | ||
@@ -189,3 +205,3 @@ } | ||
var scrollables = []; | ||
var $div = document.createElement("div"); | ||
var $div = doc.createElement("div"); | ||
@@ -219,3 +235,4 @@ for (var i = 0; i < elements.length; i++) { | ||
var scrollables = getScrollable(selectors, direction, false); | ||
return scrollables.length >= 1 ? scrollables[0] : undefined; | ||
return scrollables.length >= 1 ? scrollables[0] : null; | ||
} | ||
@@ -228,7 +245,7 @@ | ||
function getHeight(el) { | ||
return Math.max(el.scrollHeight, el.clientHeight, el.offsetHeight); | ||
return max(el.scrollHeight, el.clientHeight, el.offsetHeight); | ||
} | ||
function getWidth(el) { | ||
return Math.max(el.scrollWidth, el.clientWidth, el.offsetWidth); | ||
return max(el.scrollWidth, el.clientWidth, el.offsetWidth); | ||
} | ||
@@ -245,4 +262,4 @@ | ||
return { | ||
width: Math.max(getWidth(document.body), getWidth(document.documentElement)), | ||
height: Math.max(getHeight(document.body), getHeight(document.documentElement)) | ||
width: max(getWidth(doc.body), getWidth(doc.documentElement)), | ||
height: max(getHeight(doc.body), getHeight(doc.documentElement)) | ||
}; | ||
@@ -255,4 +272,4 @@ } | ||
viewport: { | ||
width: Math.min(window.innerWidth, document.documentElement.clientWidth), | ||
height: window.innerHeight | ||
width: min(win.innerWidth, doc.documentElement.clientWidth), | ||
height: win.innerHeight | ||
}, | ||
@@ -264,3 +281,6 @@ size: getDocumentSize() | ||
return { | ||
viewport: { width: el.clientWidth, height: el.clientHeight }, | ||
viewport: { | ||
width: el.clientWidth, | ||
height: el.clientHeight | ||
}, | ||
size: getSize(el) | ||
@@ -273,4 +293,5 @@ }; | ||
var win = getWindow(el); | ||
return win ? win[directionPropMap[direction]] : el[directionMethodMap[direction]]; | ||
var currentWindow = getWindow(el); | ||
return currentWindow ? currentWindow[directionPropMap[direction]] : el[directionMethodMap[direction]]; | ||
} | ||
@@ -281,6 +302,6 @@ | ||
var win = getWindow(el); | ||
var currentWindow = getWindow(el); | ||
var top = direction === "y"; | ||
if (win) { | ||
win.scrollTo(!top ? offset : win[directionPropMap.x], top ? offset : win[directionPropMap.y]); | ||
if (currentWindow) { | ||
currentWindow.scrollTo(!top ? offset : currentWindow[directionPropMap.x], top ? offset : currentWindow[directionPropMap.y]); | ||
} else { | ||
@@ -297,10 +318,12 @@ el[directionMethodMap[direction]] = offset; | ||
} | ||
var rect = el.getBoundingClientRect(); | ||
if (rect.width || rect.height) { | ||
var scroll = {}; | ||
var ctx = void 0; | ||
var ctx = null; | ||
if (context == null || isRootContainer(context)) { | ||
ctx = el.ownerDocument.documentElement; | ||
scroll.top = window.pageYOffset; | ||
scroll.left = window.pageXOffset; | ||
scroll.top = win.pageYOffset; | ||
scroll.left = win.pageXOffset; | ||
} else { | ||
@@ -312,2 +335,3 @@ ctx = context; | ||
} | ||
return { | ||
@@ -318,2 +342,3 @@ top: rect.top + scroll.top - ctx.clientTop, | ||
} | ||
return rect; | ||
@@ -328,2 +353,3 @@ } | ||
} | ||
return window.history && "pushState" in window.history && window.location.protocol !== "file:"; | ||
@@ -346,11 +372,2 @@ }(); | ||
var math = Math; | ||
var mathCos = math.cos; | ||
var mathSin = math.sin; | ||
var mathPow = math.pow; | ||
var mathAbs = math.abs; | ||
var mathSqrt = math.sqrt; | ||
var mathAsin = math.asin; | ||
var PI = math.PI; | ||
function linear(p) { | ||
@@ -421,19 +438,19 @@ return p; | ||
function InSine(x, t, b, c, d) { | ||
return -c * mathCos(t / d * (PI / 2)) + c + b; | ||
return -c * cos(t / d * (PI / 2)) + c + b; | ||
} | ||
function OutSine(x, t, b, c, d) { | ||
return c * mathSin(t / d * (PI / 2)) + b; | ||
return c * sin(t / d * (PI / 2)) + b; | ||
} | ||
function InOutSine(x, t, b, c, d) { | ||
return -c / 2 * (mathCos(PI * t / d) - 1) + b; | ||
return -c / 2 * (cos(PI * t / d) - 1) + b; | ||
} | ||
function InExpo(x, t, b, c, d) { | ||
return t === 0 ? b : c * mathPow(2, 10 * (t / d - 1)) + b; | ||
return t === 0 ? b : c * pow(2, 10 * (t / d - 1)) + b; | ||
} | ||
function OutExpo(x, t, b, c, d) { | ||
return t === d ? b + c : c * (-mathPow(2, -10 * t / d) + 1) + b; | ||
return t === d ? b + c : c * (-pow(2, -10 * t / d) + 1) + b; | ||
} | ||
@@ -444,12 +461,12 @@ | ||
if (t === d) return b + c; | ||
if ((t /= d / 2) < 1) return c / 2 * mathPow(2, 10 * (t - 1)) + b; | ||
return c / 2 * (-mathPow(2, -10 * --t) + 2) + b; | ||
if ((t /= d / 2) < 1) return c / 2 * pow(2, 10 * (t - 1)) + b; | ||
return c / 2 * (-pow(2, -10 * --t) + 2) + b; | ||
} | ||
function InCirc(x, t, b, c, d) { | ||
return -c * (mathSqrt(1 - (t /= d) * t) - 1) + b; | ||
return -c * (sqrt(1 - (t /= d) * t) - 1) + b; | ||
} | ||
function OutCirc(x, t, b, c, d) { | ||
return c * mathSqrt(1 - (t = t / d - 1) * t) + b; | ||
return c * sqrt(1 - (t = t / d - 1) * t) + b; | ||
} | ||
@@ -459,56 +476,56 @@ | ||
if ((t /= d / 2) < 1) { | ||
return -c / 2 * (mathSqrt(1 - t * t) - 1) + b; | ||
return -c / 2 * (sqrt(1 - t * t) - 1) + b; | ||
} | ||
return c / 2 * (mathSqrt(1 - (t -= 2) * t) + 1) + b; | ||
return c / 2 * (sqrt(1 - (t -= 2) * t) + 1) + b; | ||
} | ||
function InElastic(x, t, b, c, d) { | ||
var s = 1.70158, | ||
p = 0, | ||
a = c; | ||
var s = 1.70158; | ||
var p = 0; | ||
var a = c; | ||
if (t === 0) return b; | ||
if ((t /= d) === 1) return b + c; | ||
if (!p) p = d * .3; | ||
if (a < mathAbs(c)) { | ||
if (a < abs(c)) { | ||
a = c; | ||
s = p / 4; | ||
} else { | ||
s = p / (2 * PI) * mathAsin(c / a); | ||
s = p / (2 * PI) * asin(c / a); | ||
} | ||
return -(a * mathPow(2, 10 * (t -= 1)) * mathSin((t * d - s) * (2 * PI) / p)) + b; | ||
return -(a * pow(2, 10 * (t -= 1)) * sin((t * d - s) * (2 * PI) / p)) + b; | ||
} | ||
function OutElastic(x, t, b, c, d) { | ||
var s = 1.70158, | ||
p = 0, | ||
a = c; | ||
var s = 1.70158; | ||
var p = 0; | ||
var a = c; | ||
if (t === 0) return b; | ||
if ((t /= d) === 1) return b + c; | ||
if (!p) p = d * .3; | ||
if (a < mathAbs(c)) { | ||
if (a < abs(c)) { | ||
a = c; | ||
s = p / 4; | ||
} else { | ||
s = p / (2 * PI) * mathAsin(c / a); | ||
s = p / (2 * PI) * asin(c / a); | ||
} | ||
return a * mathPow(2, -10 * t) * mathSin((t * d - s) * (2 * PI) / p) + c + b; | ||
return a * pow(2, -10 * t) * sin((t * d - s) * (2 * PI) / p) + c + b; | ||
} | ||
function InOutElastic(x, t, b, c, d) { | ||
var s = 1.70158, | ||
p = 0, | ||
a = c; | ||
var s = 1.70158; | ||
var p = 0; | ||
var a = c; | ||
if (t === 0) return b; | ||
if ((t /= d / 2) === 2) return b + c; | ||
if (!p) p = d * (.3 * 1.5); | ||
if (a < mathAbs(c)) { | ||
if (a < abs(c)) { | ||
a = c; | ||
s = p / 4; | ||
} else { | ||
s = p / (2 * PI) * mathAsin(c / a); | ||
s = p / (2 * PI) * asin(c / a); | ||
} | ||
if (t < 1) { | ||
return -.5 * (a * mathPow(2, 10 * (t -= 1)) * mathSin((t * d - s) * (2 * PI) / p)) + b; | ||
return -.5 * (a * pow(2, 10 * (t -= 1)) * sin((t * d - s) * (2 * PI) / p)) + b; | ||
} | ||
return a * mathPow(2, -10 * (t -= 1)) * mathSin((t * d - s) * (2 * PI) / p) * .5 + c + b; | ||
return a * pow(2, -10 * (t -= 1)) * sin((t * d - s) * (2 * PI) / p) * .5 + c + b; | ||
} | ||
@@ -537,6 +554,2 @@ | ||
function InBounce(x, t, b, c, d) { | ||
return c - OutBounce(x, d - t, 0, c, d) + b; | ||
} | ||
function OutBounce(x, t, b, c, d) { | ||
@@ -554,2 +567,6 @@ if ((t /= d) < 1 / 2.75) { | ||
function InBounce(x, t, b, c, d) { | ||
return c - OutBounce(x, d - t, 0, c, d) + b; | ||
} | ||
function InOutBounce(x, t, b, c, d) { | ||
@@ -591,19 +608,38 @@ if (t < d / 2) { | ||
InOutBack: InOutBack, | ||
OutBounce: OutBounce, | ||
InBounce: InBounce, | ||
OutBounce: OutBounce, | ||
InOutBounce: InOutBounce | ||
}); | ||
var vendors = ["ms", "moz", "webkit"]; | ||
var lastTime = 0; | ||
var raf = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function (callback) { | ||
var currentTime = Date.now(); | ||
var timeToCall = Math.max(0, 16 - (currentTime - lastTime)); | ||
var id = window.setTimeout(function () { | ||
callback(currentTime + timeToCall); | ||
}, timeToCall); | ||
lastTime = currentTime + timeToCall; | ||
return id; | ||
}; | ||
var raf = win.requestAnimationFrame; | ||
var caf = win.cancelAnimationFrame; | ||
for (var x = 0; x < vendors.length && !raf; ++x) { | ||
raf = win[vendors[x] + "RequestAnimationFrame"]; | ||
caf = win[vendors[x] + "CancelAnimationFrame"] || win[vendors[x] + "CancelRequestAnimationFrame"]; | ||
} | ||
if (!raf) { | ||
raf = function raf(callback) { | ||
var currentTime = Date.now(); | ||
var timeToCall = max(0, 16 - (currentTime - lastTime)); | ||
var id = setTimeout(function () { | ||
callback(currentTime + timeToCall); | ||
}, timeToCall); | ||
lastTime = currentTime + timeToCall; | ||
return id; | ||
}; | ||
} | ||
if (!caf) { | ||
caf = function caf(id) { | ||
clearTimeout(id); | ||
}; | ||
} | ||
var ScrollTween = function () { | ||
@@ -617,3 +653,5 @@ function ScrollTween(el) { | ||
this.progress = false; | ||
this.easing = null; | ||
this.startTime = null; | ||
this.rafId = null; | ||
} | ||
@@ -629,3 +667,3 @@ | ||
this.options = options; | ||
this.options.easing = options.easing.replace("ease", ""); | ||
this.easing = isFunction(options.easing) ? options.easing : Easing[options.easing.replace("ease", "")]; | ||
this.progress = true; | ||
@@ -638,3 +676,3 @@ | ||
}; | ||
raf(function (time) { | ||
_this.rafId = raf(function (time) { | ||
return _this._loop(time); | ||
@@ -652,2 +690,3 @@ }); | ||
this.progress = false; | ||
caf(this.rafId); | ||
@@ -675,2 +714,3 @@ if (gotoEnd) { | ||
this.stop(false); | ||
return; | ||
@@ -684,2 +724,3 @@ } | ||
var startProps = this.startProps; | ||
var easing = this.easing; | ||
var duration = options.duration; | ||
@@ -689,5 +730,4 @@ var step = options.step; | ||
var toProps = {}; | ||
var easing = Easing[this.options.easing]; | ||
var timeElapsed = time - startTime; | ||
var t = Math.min(1, Math.max(timeElapsed / duration, 0)); | ||
var t = min(1, max(timeElapsed / duration, 0)); | ||
@@ -700,3 +740,3 @@ each(props, function (value, key) { | ||
var val = easing(t, duration * t, 0, 1, duration); | ||
toProps[key] = Math.round(initialValue + delta * val); | ||
toProps[key] = round(initialValue + delta * val); | ||
}); | ||
@@ -710,4 +750,4 @@ | ||
step.call(this, t, toProps); | ||
raf(function (time) { | ||
return _this2._loop(time); | ||
this.rafId = raf(function (currentTime) { | ||
return _this2._loop(currentTime); | ||
}); | ||
@@ -722,5 +762,12 @@ } else { | ||
var win = window; | ||
var doc = document; | ||
var WHEEL_EVENT = "onwheel" in doc ? "wheel" : "onmousewheel" in doc ? "mousewheel" : "DOMMouseScroll"; | ||
var WHEEL_EVENT = function () { | ||
if ("onwheel" in doc) { | ||
return "wheel"; | ||
} else if ("onmousewheel" in doc) { | ||
return "mousewheel"; | ||
} else { | ||
return "DOMMouseScroll"; | ||
} | ||
}(); | ||
var CONTAINER_STOP_EVENTS = WHEEL_EVENT + ", touchstart, touchmove"; | ||
@@ -736,6 +783,9 @@ var DOM_CONTENT_LOADED = "DOMContentLoaded"; | ||
/* eslint-disable max-len */ | ||
/** | ||
* SweetScroll constructor | ||
* @param {Object} | ||
* @param {String} | {Element} | ||
* @constructor | ||
* @param {Object} options | ||
* @param {String | Element} container | ||
*/ | ||
@@ -751,2 +801,3 @@ | ||
var params = merge({}, SweetScroll.defaults, options); | ||
this.options = params; | ||
@@ -766,5 +817,5 @@ this.getContainer(container, function (target) { | ||
* Scroll animation to the specified position | ||
* @param {Any} | ||
* @param {Object} | ||
* @return {Void} | ||
* @param {*} distance | ||
* @param {Object} options | ||
* @return {void} | ||
*/ | ||
@@ -774,2 +825,3 @@ | ||
// Default options | ||
/* eslint-disable max-len */ | ||
@@ -813,3 +865,6 @@ | ||
if (distance === "#") { | ||
scroll = { top: 0, left: 0 }; | ||
scroll = { | ||
top: 0, | ||
left: 0 | ||
}; | ||
} else { | ||
@@ -833,3 +888,3 @@ var target = $(distance); | ||
if (header) { | ||
scroll.top = Math.max(0, scroll.top - getSize(header).height); | ||
scroll.top = max(0, scroll.top - getSize(header).height); | ||
} | ||
@@ -852,4 +907,4 @@ | ||
// Adjustment of the maximum value | ||
scroll.top = params.verticalScroll ? Math.max(0, Math.min(size.height - viewport.height, scroll.top)) : getScroll(container, "y"); | ||
scroll.left = params.horizontalScroll ? Math.max(0, Math.min(size.width - viewport.width, scroll.left)) : getScroll(container, "x"); | ||
scroll.top = params.verticalScroll ? max(0, min(size.height - viewport.height, scroll.top)) : getScroll(container, "y"); | ||
scroll.left = params.horizontalScroll ? max(0, min(size.width - viewport.width, scroll.left)) : getScroll(container, "x"); | ||
@@ -894,5 +949,5 @@ // Run the animation!! | ||
* Scroll animation to the specified top position | ||
* @param {Any} | ||
* @param {Object} | ||
* @return {Void} | ||
* @param {*} distance | ||
* @param {Object} options | ||
* @return {void} | ||
*/ | ||
@@ -913,5 +968,5 @@ | ||
* Scroll animation to the specified left position | ||
* @param {Any} | ||
* @param {Object} | ||
* @return {Void} | ||
* @param {*} distance | ||
* @param {Object} options | ||
* @return {void} | ||
*/ | ||
@@ -932,5 +987,5 @@ | ||
* Scroll animation to the specified element | ||
* @param {Element} | ||
* @param {Object} | ||
* @return {Void} | ||
* @param {Element} el | ||
* @param {Object} options | ||
* @return {void} | ||
*/ | ||
@@ -940,7 +995,7 @@ | ||
key: "toElement", | ||
value: function toElement($el) { | ||
value: function toElement(el) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
if ($el instanceof Element) { | ||
var offset = getOffset($el, this.container); | ||
if (el instanceof Element) { | ||
var offset = getOffset(el, this.container); | ||
this.to(offset, merge({}, options)); | ||
@@ -952,4 +1007,4 @@ } | ||
* Stop the current animation | ||
* @param {Boolean} | ||
* @return {Void} | ||
* @param {Boolean} gotoEnd | ||
* @return {void} | ||
*/ | ||
@@ -970,4 +1025,4 @@ | ||
* Update the instance | ||
* @param {Object} | ||
* @return {Void} | ||
* @param {Object} options | ||
* @return {void} | ||
*/ | ||
@@ -990,4 +1045,3 @@ | ||
* Destroy SweetScroll instance | ||
* @param {Boolean} | ||
* @return {Void} | ||
* @return {void} | ||
*/ | ||
@@ -1008,3 +1062,3 @@ | ||
* Called at after of the initialize. | ||
* @return {Void} | ||
* @return {void} | ||
*/ | ||
@@ -1018,6 +1072,7 @@ | ||
* Called at before of the scroll. | ||
* @param {Object} | ||
* @param {Element} | ||
* @param {Object} toScroll | ||
* @param {Element} trigger | ||
* @return {Boolean} | ||
*/ | ||
/* eslint-disable no-unused-vars */ | ||
@@ -1030,5 +1085,7 @@ }, { | ||
/* eslint-disable no-unused-vars */ | ||
/** | ||
* Called at cancel of the scroll. | ||
* @return {Void} | ||
* @return {void} | ||
*/ | ||
@@ -1042,5 +1099,5 @@ | ||
* Called at after of the scroll. | ||
* @param {Object} | ||
* @param {Element} | ||
* @return {Void} | ||
* @param {Object} toScroll | ||
* @param {Element} trigger | ||
* @return {void} | ||
*/ | ||
@@ -1054,4 +1111,4 @@ | ||
* Called at complete of the scroll. | ||
* @param {Boolean} | ||
* @return {Void} | ||
* @param {Boolean} isCancel | ||
* @return {void} | ||
*/ | ||
@@ -1065,5 +1122,5 @@ | ||
* Called at each animation frame of the scroll. | ||
* @param {Float} | ||
* @param {Object} | ||
* @return {Void} | ||
* @param {Float} currentTime | ||
* @param {Object} props | ||
* @return {void} | ||
*/ | ||
@@ -1077,3 +1134,3 @@ | ||
* Parse the value of coordinate | ||
* @param {Any} | ||
* @param {*} coodinate | ||
* @return {Object} | ||
@@ -1109,14 +1166,14 @@ */ | ||
} else if (isString(coodinate)) { | ||
coodinate = removeSpaces(coodinate); | ||
var trimedCoodinate = removeSpaces(coodinate); | ||
// "{n},{n}" (Array like syntax) | ||
if (/^\d+,\d+$/.test(coodinate)) { | ||
coodinate = coodinate.split(","); | ||
scroll.top = coodinate[0]; | ||
scroll.left = coodinate[1]; | ||
if (/^\d+,\d+$/.test(trimedCoodinate)) { | ||
trimedCoodinate = trimedCoodinate.split(","); | ||
scroll.top = trimedCoodinate[0]; | ||
scroll.left = trimedCoodinate[1]; | ||
// "top:{n}, left:{n}" (Object like syntax) | ||
} else if (/^(top|left):\d+,?(?:(top|left):\d+)?$/.test(coodinate)) { | ||
var top = coodinate.match(/top:(\d+)/); | ||
var left = coodinate.match(/left:(\d+)/); | ||
} else if (/^(top|left):\d+,?(?:(top|left):\d+)?$/.test(trimedCoodinate)) { | ||
var top = trimedCoodinate.match(/top:(\d+)/); | ||
var left = trimedCoodinate.match(/left:(\d+)/); | ||
scroll.top = top ? top[1] : 0; | ||
@@ -1126,7 +1183,7 @@ scroll.left = left ? left[1] : 0; | ||
// "+={n}", "-={n}" (Relative position) | ||
} else if (this.container && /^(\+|-)=(\d+)$/.test(coodinate)) { | ||
} else if (this.container && /^(\+|-)=(\d+)$/.test(trimedCoodinate)) { | ||
var current = getScroll(this.container, enableTop ? "y" : "x"); | ||
var _matches = coodinate.match(/^(\+|-)\=(\d+)$/); | ||
var op = _matches[1]; | ||
var value = parseInt(_matches[2], 10); | ||
var results = trimedCoodinate.match(/^(\+|-)=(\d+)$/); | ||
var op = results[1]; | ||
var value = parseInt(results[2], 10); | ||
if (op === "+") { | ||
@@ -1154,5 +1211,5 @@ scroll.top = enableTop ? current + value : 0; | ||
* Update the Hash of the URL. | ||
* @param {String} | ||
* @param {Boolean} | {String} | ||
* @return {Void} | ||
* @param {String} hash | ||
* @param {Boolean | String} historyType | ||
* @return {void} | ||
*/ | ||
@@ -1169,5 +1226,5 @@ | ||
* Get the container for the scroll, depending on the options. | ||
* @param {String} | {Element} | ||
* @param {Function} | ||
* @return {Void} | ||
* @param {String | Element} selector | ||
* @param {Function} callback | ||
* @return {void} | ||
* @private | ||
@@ -1185,3 +1242,3 @@ */ | ||
var container = void 0; | ||
var container = null; | ||
@@ -1219,3 +1276,3 @@ if (verticalScroll) { | ||
* Bind a click event to the container | ||
* @return {Void} | ||
* @return {void} | ||
* @private | ||
@@ -1236,3 +1293,3 @@ */ | ||
* Unbind a click event to the container | ||
* @return {Void} | ||
* @return {void} | ||
* @private | ||
@@ -1253,3 +1310,3 @@ */ | ||
* Bind the scroll stop of events | ||
* @return {Void} | ||
* @return {void} | ||
* @private | ||
@@ -1270,3 +1327,3 @@ */ | ||
* Unbind the scroll stop of events | ||
* @return {Void} | ||
* @return {void} | ||
* @private | ||
@@ -1287,6 +1344,6 @@ */ | ||
* Call the specified callback | ||
* @param {Object} | ||
* @param {String} | ||
* @param {...Any} | ||
* @return {Void} | ||
* @param {Object} options | ||
* @param {String} type | ||
* @param {...*} args | ||
* @return {void} | ||
* @private | ||
@@ -1308,3 +1365,3 @@ */ | ||
var result = callback.apply(this, args); | ||
if (result !== undefined) return result; | ||
if (typeof result === "undefined") return result; | ||
} | ||
@@ -1318,4 +1375,4 @@ | ||
* Handling of scroll stop event | ||
* @param {Event} | ||
* @return {Void} | ||
* @param {Event} e | ||
* @return {void} | ||
* @private | ||
@@ -1337,4 +1394,4 @@ */ | ||
* Handling of container click event | ||
* @param {Event} | ||
* @return {Void} | ||
* @param {Event} e | ||
* @return {void} | ||
* @private | ||
@@ -1377,3 +1434,3 @@ */ | ||
* Parse the data-scroll-options attribute | ||
* @param {Element} | ||
* @param {Element} el | ||
* @return {Object} | ||
@@ -1387,2 +1444,3 @@ * @private | ||
var options = el.getAttribute("data-scroll-options"); | ||
return options ? JSON.parse(options) : {}; | ||
@@ -1389,0 +1447,0 @@ } |
/*! | ||
* sweet-scroll | ||
* Modern and the sweet smooth scroll library. | ||
* | ||
* @author tsuyoshiwada | ||
* @homepage https://github.com/tsuyoshiwada/sweet-scroll | ||
* @license MIT | ||
* @version 0.7.1 | ||
* @version 1.0.0 | ||
*/ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.SweetScroll=n()}(this,function(){"use strict";function t(t){return null==t?t+"":"object"===("undefined"==typeof t?"undefined":lt["typeof"](t))||"function"==typeof t?ct[Object.prototype.toString.call(t)]||"object":"undefined"==typeof t?"undefined":lt["typeof"](t)}function n(t){return Array.isArray(t)}function e(t){var n=null==t?null:t.length;return i(n)&&n>=0&&ut>=n}function o(e){return!n(e)&&"object"===t(e)}function i(n){return"number"===t(n)}function r(n){return"string"===t(n)}function l(n){return"function"===t(n)}function u(t){return!n(t)&&t-parseFloat(t)+1>=0}function a(t,n){return t&&t.hasOwnProperty(n)}function c(t){for(var n=arguments.length,e=Array(n>1?n-1:0),o=1;n>o;o++)e[o-1]=arguments[o];return s(e,function(n){s(n,function(n,e){t[e]=n})}),t}function s(t,n,i){if(null==t)return t;if(i=i||t,o(t)){for(var r in t)if(a(t,r)&&n.call(i,t[r],r)===!1)break}else if(e(t)){var l=void 0,u=t.length;for(l=0;u>l&&n.call(i,t[l],l)!==!1;l++);}return t}function h(t){return t.replace(/\s*/g,"")||""}function f(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==n?document:n).querySelector(t)}function p(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==n?document:n).querySelectorAll(t)}function d(t,n){for(var e=(t.document||t.ownerDocument).querySelectorAll(n),o=e.length;--o>=0&&e.item(o)!==t;);return o>-1}function v(t){var n=document;return t===n.documentElement||t===n.body}function g(t){for(var n=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],e=arguments.length<=2||void 0===arguments[2]?!0:arguments[2],o=st[n],i=t instanceof Element?[t]:p(t),r=[],l=document.createElement("div"),u=0;u<i.length;u++){var a=i[u];if(a[o]>0?r.push(a):(l.style.width=a.clientWidth+1+"px",l.style.height=a.clientHeight+1+"px",a.appendChild(l),a[o]=1,a[o]>0&&r.push(a),a[o]=0,a.removeChild(l)),!e&&r.length>0)break}return r}function y(t,n){var e=g(t,n,!1);return e.length>=1?e[0]:void 0}function m(t){return null!=t&&t===t.window?t:9===t.nodeType&&t.defaultView}function S(t){return Math.max(t.scrollHeight,t.clientHeight,t.offsetHeight)}function C(t){return Math.max(t.scrollWidth,t.clientWidth,t.offsetWidth)}function w(t){return{width:C(t),height:S(t)}}function k(){return{width:Math.max(C(document.body),C(document.documentElement)),height:Math.max(S(document.body),S(document.documentElement))}}function b(t){return v(t)?{viewport:{width:Math.min(window.innerWidth,document.documentElement.clientWidth),height:window.innerHeight},size:k()}:{viewport:{width:t.clientWidth,height:t.clientHeight},size:w(t)}}function O(t){var n=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],e=m(t);return e?e[ht[n]]:t[st[n]]}function x(t,n){var e=arguments.length<=2||void 0===arguments[2]?"y":arguments[2],o=m(t),i="y"===e;o?o.scrollTo(i?o[ht.x]:n,i?n:o[ht.y]):t[st[e]]=n}function _(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(!t||t&&!t.getClientRects().length)return{top:0,left:0};var e=t.getBoundingClientRect();if(e.width||e.height){var o={},i=void 0;if(null==n||v(n))i=t.ownerDocument.documentElement,o.top=window.pageYOffset,o.left=window.pageXOffset;else{i=n;var r=i.getBoundingClientRect();o.top=-1*r.top+i.scrollTop,o.left=-1*r.left+i.scrollLeft}return{top:e.top+o.top-i.clientTop,left:e.left+o.left-i.clientLeft}}return e}function I(t,n,e){var o=n.split(",");o.forEach(function(n){t.addEventListener(n.trim(),e,!1)})}function L(t,n,e){var o=n.split(",");o.forEach(function(n){t.removeEventListener(n.trim(),e,!1)})}function E(t){return t}function M(t,n,e,o,i){return o*(n/=i)*n+e}function A(t,n,e,o,i){return-o*(n/=i)*(n-2)+e}function z(t,n,e,o,i){return(n/=i/2)<1?o/2*n*n+e:-o/2*(--n*(n-2)-1)+e}function T(t,n,e,o,i){return o*(n/=i)*n*n+e}function D(t,n,e,o,i){return o*((n=n/i-1)*n*n+1)+e}function Q(t,n,e,o,i){return(n/=i/2)<1?o/2*n*n*n+e:o/2*((n-=2)*n*n+2)+e}function j(t,n,e,o,i){return o*(n/=i)*n*n*n+e}function B(t,n,e,o,i){return-o*((n=n/i-1)*n*n*n-1)+e}function P(t,n,e,o,i){return(n/=i/2)<1?o/2*n*n*n*n+e:-o/2*((n-=2)*n*n*n-2)+e}function R(t,n,e,o,i){return o*(n/=i)*n*n*n*n+e}function H(t,n,e,o,i){return o*((n=n/i-1)*n*n*n*n+1)+e}function W(t,n,e,o,i){return(n/=i/2)<1?o/2*n*n*n*n*n+e:o/2*((n-=2)*n*n*n*n+2)+e}function q(t,n,e,o,i){return-o*dt(n/i*(Ct/2))+o+e}function F(t,n,e,o,i){return o*vt(n/i*(Ct/2))+e}function U(t,n,e,o,i){return-o/2*(dt(Ct*n/i)-1)+e}function $(t,n,e,o,i){return 0===n?e:o*gt(2,10*(n/i-1))+e}function N(t,n,e,o,i){return n===i?e+o:o*(-gt(2,-10*n/i)+1)+e}function X(t,n,e,o,i){return 0===n?e:n===i?e+o:(n/=i/2)<1?o/2*gt(2,10*(n-1))+e:o/2*(-gt(2,-10*--n)+2)+e}function Y(t,n,e,o,i){return-o*(mt(1-(n/=i)*n)-1)+e}function J(t,n,e,o,i){return o*mt(1-(n=n/i-1)*n)+e}function V(t,n,e,o,i){return(n/=i/2)<1?-o/2*(mt(1-n*n)-1)+e:o/2*(mt(1-(n-=2)*n)+1)+e}function G(t,n,e,o,i){var r=1.70158,l=0,u=o;return 0===n?e:1===(n/=i)?e+o:(l||(l=.3*i),u<yt(o)?(u=o,r=l/4):r=l/(2*Ct)*St(o/u),-(u*gt(2,10*(n-=1))*vt((n*i-r)*(2*Ct)/l))+e)}function K(t,n,e,o,i){var r=1.70158,l=0,u=o;return 0===n?e:1===(n/=i)?e+o:(l||(l=.3*i),u<yt(o)?(u=o,r=l/4):r=l/(2*Ct)*St(o/u),u*gt(2,-10*n)*vt((n*i-r)*(2*Ct)/l)+o+e)}function Z(t,n,e,o,i){var r=1.70158,l=0,u=o;return 0===n?e:2===(n/=i/2)?e+o:(l||(l=i*(.3*1.5)),u<yt(o)?(u=o,r=l/4):r=l/(2*Ct)*St(o/u),1>n?-.5*(u*gt(2,10*(n-=1))*vt((n*i-r)*(2*Ct)/l))+e:u*gt(2,-10*(n-=1))*vt((n*i-r)*(2*Ct)/l)*.5+o+e)}function tt(t,n,e,o,i){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return o*(n/=i)*n*((r+1)*n-r)+e}function nt(t,n,e,o,i){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return o*((n=n/i-1)*n*((r+1)*n+r)+1)+e}function et(t,n,e,o,i){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return(n/=i/2)<1?o/2*(n*n*(((r*=1.525)+1)*n-r))+e:o/2*((n-=2)*n*(((r*=1.525)+1)*n+r)+2)+e}function ot(t,n,e,o,i){return o-it(t,i-n,0,o,i)+e}function it(t,n,e,o,i){return(n/=i)<1/2.75?o*(7.5625*n*n)+e:2/2.75>n?o*(7.5625*(n-=1.5/2.75)*n+.75)+e:2.5/2.75>n?o*(7.5625*(n-=2.25/2.75)*n+.9375)+e:o*(7.5625*(n-=2.625/2.75)*n+.984375)+e}function rt(t,n,e,o,i){return i/2>n?.5*ot(t,2*n,0,o,i)+e:.5*it(t,2*n-i,0,o,i)+.5*o+e}var lt={};lt["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},lt.classCallCheck=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")},lt.createClass=function(){function t(t,n){for(var e=0;e<n.length;e++){var o=n[e];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(n,e,o){return e&&t(n.prototype,e),o&&t(n,o),n}}();var ut=Math.pow(2,53)-1,at=["Boolean","Number","String","Function","Array","Object"],ct={};at.forEach(function(t){ct["[object "+t+"]"]=t.toLowerCase()});var st={y:"scrollTop",x:"scrollLeft"},ht={y:"pageYOffset",x:"pageXOffset"},ft=function(){var t=navigator.userAgent;return-1===t.indexOf("Android 2.")&&-1===t.indexOf("Android 4.0")||-1===t.indexOf("Mobile Safari")||-1!==t.indexOf("Chrome")||-1!==t.indexOf("Windows Phone")?window.history&&"pushState"in window.history&&"file:"!==window.location.protocol:!1}(),pt=Math,dt=pt.cos,vt=pt.sin,gt=pt.pow,yt=pt.abs,mt=pt.sqrt,St=pt.asin,Ct=pt.PI,wt=Object.freeze({linear:E,InQuad:M,OutQuad:A,InOutQuad:z,InCubic:T,OutCubic:D,InOutCubic:Q,InQuart:j,OutQuart:B,InOutQuart:P,InQuint:R,OutQuint:H,InOutQuint:W,InSine:q,OutSine:F,InOutSine:U,InExpo:$,OutExpo:N,InOutExpo:X,InCirc:Y,OutCirc:J,InOutCirc:V,InElastic:G,OutElastic:K,InOutElastic:Z,InBack:tt,OutBack:nt,InOutBack:et,InBounce:ot,OutBounce:it,InOutBounce:rt}),kt=0,bt=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){var n=Date.now(),e=Math.max(0,16-(n-kt)),o=window.setTimeout(function(){t(n+e)},e);return kt=n+e,o},Ot=function(){function t(n){lt.classCallCheck(this,t),this.el=n,this.props={},this.options={},this.progress=!1,this.startTime=null}return lt.createClass(t,[{key:"run",value:function(t,n,e){var o=this;this.progress||(this.props={x:t,y:n},this.options=e,this.options.easing=e.easing.replace("ease",""),this.progress=!0,setTimeout(function(){o.startProps={x:O(o.el,"x"),y:O(o.el,"y")},bt(function(t){return o._loop(t)})},this.options.delay))}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!0:arguments[0],n=this.options.complete;this.startTime=null,this.progress=!1,t&&(x(this.el,this.props.x,"x"),x(this.el,this.props.y,"y")),l(n)&&(n.call(this),this.options.complete=null)}},{key:"_loop",value:function(t){var n=this;if(this.startTime||(this.startTime=t),!this.progress)return void this.stop(!1);var e=this.el,o=this.props,i=this.options,r=this.startTime,l=this.startProps,u=i.duration,a=i.step,c={},h=wt[this.options.easing],f=t-r,p=Math.min(1,Math.max(f/u,0));s(o,function(t,n){var e=l[n],o=t-e;if(0===o)return!0;var i=h(p,u*p,0,1,u);c[n]=Math.round(e+o*i)}),s(c,function(t,n){x(e,t,n)}),u>=f?(a.call(this,p,c),bt(function(t){return n._loop(t)})):this.stop(!0)}}]),t}(),xt=window,_t=document,It="onwheel"in _t?"wheel":"onmousewheel"in _t?"mousewheel":"DOMMouseScroll",Lt=It+", touchstart, touchmove",Et="DOMContentLoaded",Mt=!1;I(_t,Et,function(){Mt=!0});var At=function(){function t(){var n=this,e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],o=arguments.length<=1||void 0===arguments[1]?"body, html":arguments[1];lt.classCallCheck(this,t);var i=c({},t.defaults,e);this.options=i,this.getContainer(o,function(t){n.container=t,n.header=f(i.header),n.tween=new Ot(t),n._trigger=null,n._shouldCallCancelScroll=!1,n.bindContainerClick(),n.hook(i,"initialized")})}return lt.createClass(t,[{key:"to",value:function(t){var n=this,e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],o=this.container,i=this.header,l=c({},this.options,e);this._options=l;var u=this.parseCoodinate(l.offset),a=this._trigger,s=this.parseCoodinate(t),h=null;if(this._trigger=null,this._shouldCallCancelScroll=!1,this.stop(),o){if(!s&&r(t))if(h=/^#/.test(t)?t:null,"#"===t)s={top:0,left:0};else{var p=f(t),d=_(p,o);if(!d)return;s=d}if(s){u&&(s.top+=u.top,s.left+=u.left),i&&(s.top=Math.max(0,s.top-w(i).height));var v=b(o),g=v.viewport,y=v.size;this.hook(l,"beforeScroll",s,a)!==!1&&(s.top=l.verticalScroll?Math.max(0,Math.min(y.height-g.height,s.top)):O(o,"y"),s.left=l.horizontalScroll?Math.max(0,Math.min(y.width-g.width,s.left)):O(o,"x"),this.tween.run(s.left,s.top,{duration:l.duration,delay:l.delay,easing:l.easing,complete:function(){null!=h&&h!==window.location.hash&&n.updateURLHash(h,l.updateURL),n.unbindContainerStop(),n._options=null,n._shouldCallCancelScroll?n.hook(l,"cancelScroll"):n.hook(l,"afterScroll",s,a),n.hook(l,"completeScroll",n._shouldCallCancelScroll)},step:function(t,e){n.hook(l,"stepScroll",t,e)}}),this.bindContainerStop())}}}},{key:"toTop",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,c({},n,{verticalScroll:!0,horizontalScroll:!1}))}},{key:"toLeft",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,c({},n,{verticalScroll:!1,horizontalScroll:!0}))}},{key:"toElement",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(t instanceof Element){var e=_(t,this.container);this.to(e,c({},n))}}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];this._stopScrollListener&&(this._shouldCallCancelScroll=!0),this.tween.stop(t)}},{key:"update",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];this.stop(),this.unbindContainerClick(),this.unbindContainerStop(),this.options=c({},this.options,t),this.header=f(this.options.header),this.bindContainerClick()}},{key:"destroy",value:function(){this.stop(),this.unbindContainerClick(),this.unbindContainerStop(),this.container=null,this.header=null,this.tween=null}},{key:"initialized",value:function(){}},{key:"beforeScroll",value:function(t,n){return!0}},{key:"cancelScroll",value:function(){}},{key:"afterScroll",value:function(t,n){}},{key:"completeScroll",value:function(t){}},{key:"stepScroll",value:function(t,n){}},{key:"parseCoodinate",value:function(t){var e=this._options?this._options.verticalScroll:this.options.verticalScroll,o={top:0,left:0};if(a(t,"top")||a(t,"left"))o=c(o,t);else if(n(t))2===t.length?(o.top=t[0],o.left=t[1]):(o.top=e?t[0]:0,o.left=e?0:t[0]);else if(u(t))o.top=e?t:0,o.left=e?0:t;else{if(!r(t))return null;if(t=h(t),/^\d+,\d+$/.test(t))t=t.split(","),o.top=t[0],o.left=t[1];else if(/^(top|left):\d+,?(?:(top|left):\d+)?$/.test(t)){var i=t.match(/top:(\d+)/),l=t.match(/left:(\d+)/);o.top=i?i[1]:0,o.left=l?l[1]:0}else{if(!this.container||!/^(\+|-)=(\d+)$/.test(t))return null;var s=O(this.container,e?"y":"x"),f=t.match(/^(\+|-)\=(\d+)$/),p=f[1],d=parseInt(f[2],10);"+"===p?(o.top=e?s+d:0,o.left=e?0:s+d):(o.top=e?s-d:0,o.left=e?0:s-d)}}return o.top=parseInt(o.top,10),o.left=parseInt(o.left,10),o}},{key:"updateURLHash",value:function(t,n){ft&&n&&window.history["replace"===n?"replaceState":"pushState"](null,null,t)}},{key:"getContainer",value:function(t,n){var e=this,o=this.options,i=o.verticalScroll,r=o.horizontalScroll,l=void 0;i&&(l=y(t,"y")),!l&&r&&(l=y(t,"x")),l||Mt?n.call(this,l):!function(){var o=!1;I(_t,Et,function(){o=!0,e.getContainer(t,n)}),I(xt,"load",function(){o||e.getContainer(t,n)})}()}},{key:"bindContainerClick",value:function(){var t=this.container;t&&(this._containerClickListener=this.handleContainerClick.bind(this),I(t,"click",this._containerClickListener))}},{key:"unbindContainerClick",value:function(){var t=this.container;t&&this._containerClickListener&&(L(t,"click",this._containerClickListener),this._containerClickListener=null)}},{key:"bindContainerStop",value:function(){var t=this.container;t&&(this._stopScrollListener=this.handleStopScroll.bind(this),I(t,Lt,this._stopScrollListener))}},{key:"unbindContainerStop",value:function(){var t=this.container;t&&this._stopScrollListener&&(L(t,Lt,this._stopScrollListener),this._stopScrollListener=null)}},{key:"hook",value:function(t,n){for(var e=t[n],o=arguments.length,i=Array(o>2?o-2:0),r=2;o>r;r++)i[r-2]=arguments[r];if(l(e)){var u=e.apply(this,i);if(void 0!==u)return u}return this[n].apply(this,i)}},{key:"handleStopScroll",value:function(t){var n=this._options?this._options.stopScroll:this.options.stopScroll;n?this.stop():t.preventDefault()}},{key:"handleContainerClick",value:function(t){for(var n=this.options,e=t.target;e&&e!==_t;e=e.parentNode)if(d(e,n.trigger)){var o=e.getAttribute("data-scroll"),i=this.parseDataOptions(e),r=o||e.getAttribute("href");n=c({},n,i),n.preventDefault&&t.preventDefault(),n.stopPropagation&&t.stopPropagation(),this._trigger=e,n.horizontalScroll&&n.verticalScroll?this.to(r,n):n.verticalScroll?this.toTop(r,n):n.horizontalScroll&&this.toLeft(r,n)}}},{key:"parseDataOptions",value:function(t){var n=t.getAttribute("data-scroll-options");return n?JSON.parse(n):{}}}]),t}();return At.defaults={trigger:"[data-scroll]",header:"[data-scroll-header]",duration:1e3,delay:0,easing:"easeOutQuint",offset:0,verticalScroll:!0,horizontalScroll:!1,stopScroll:!0,updateURL:!1,preventDefault:!0,stopPropagation:!0,initialized:null,beforeScroll:null,afterScroll:null,cancelScroll:null,completeScroll:null,stepScroll:null},At}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.SweetScroll=n()}(this,function(){"use strict";function t(t){return null==t?"":"object"===("undefined"==typeof t?"undefined":lt["typeof"](t))||"function"==typeof t?mt[Object.prototype.toString.call(t)]||"object":"undefined"==typeof t?"undefined":lt["typeof"](t)}function n(n){return"number"===t(n)}function e(n){return"string"===t(n)}function i(n){return"function"===t(n)}function o(t){return Array.isArray(t)}function r(t){var e=null==t?null:t.length;return n(e)&&e>=0&&yt>=e}function l(t){return!o(t)&&t-parseFloat(t)+1>=0}function u(n){return!o(n)&&"object"===t(n)}function a(t,n){return t&&t.hasOwnProperty(n)}function c(t,n,e){if(null==t)return t;var i=e||t;if(u(t)){for(var o in t)if(a(t,o)&&n.call(i,t[o],o)===!1)break}else if(r(t))for(var l=0;l<t.length&&n.call(i,t[l],l)!==!1;l++);return t}function s(t){for(var n=arguments.length,e=Array(n>1?n-1:0),i=1;n>i;i++)e[i-1]=arguments[i];return c(e,function(n){c(n,function(n,e){t[e]=n})}),t}function f(t){return t.replace(/\s*/g,"")||""}function h(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==n?kt:n).querySelector(t)}function p(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==n?kt:n).querySelectorAll(t)}function d(t,n){for(var e=(t.document||t.ownerDocument).querySelectorAll(n),i=e.length;--i>=0&&e.item(i)!==t;);return i>-1}function v(t){return t===kt.documentElement||t===kt.body}function g(t){for(var n=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],e=arguments.length<=2||void 0===arguments[2]?!0:arguments[2],i=bt[n],o=t instanceof Element?[t]:p(t),r=[],l=kt.createElement("div"),u=0;u<o.length;u++){var a=o[u];if(a[i]>0?r.push(a):(l.style.width=a.clientWidth+1+"px",l.style.height=a.clientHeight+1+"px",a.appendChild(l),a[i]=1,a[i]>0&&r.push(a),a[i]=0,a.removeChild(l)),!e&&r.length>0)break}return r}function y(t,n){var e=g(t,n,!1);return e.length>=1?e[0]:null}function S(t){return null!=t&&t===t.window?t:9===t.nodeType&&t.defaultView}function m(t){return dt(t.scrollHeight,t.clientHeight,t.offsetHeight)}function C(t){return dt(t.scrollWidth,t.clientWidth,t.offsetWidth)}function k(t){return{width:C(t),height:m(t)}}function b(){return{width:dt(C(kt.body),C(kt.documentElement)),height:dt(m(kt.body),m(kt.documentElement))}}function w(t){return v(t)?{viewport:{width:vt(Ct.innerWidth,kt.documentElement.clientWidth),height:Ct.innerHeight},size:b()}:{viewport:{width:t.clientWidth,height:t.clientHeight},size:k(t)}}function O(t){var n=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],e=S(t);return e?e[wt[n]]:t[bt[n]]}function _(t,n){var e=arguments.length<=2||void 0===arguments[2]?"y":arguments[2],i=S(t),o="y"===e;i?i.scrollTo(o?i[wt.x]:n,o?n:i[wt.y]):t[bt[e]]=n}function I(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(!t||t&&!t.getClientRects().length)return{top:0,left:0};var e=t.getBoundingClientRect();if(e.width||e.height){var i={},o=null;if(null==n||v(n))o=t.ownerDocument.documentElement,i.top=Ct.pageYOffset,i.left=Ct.pageXOffset;else{o=n;var r=o.getBoundingClientRect();i.top=-1*r.top+o.scrollTop,i.left=-1*r.left+o.scrollLeft}return{top:e.top+i.top-o.clientTop,left:e.left+i.left-o.clientLeft}}return e}function x(t,n,e){var i=n.split(",");i.forEach(function(n){t.addEventListener(n.trim(),e,!1)})}function L(t,n,e){var i=n.split(",");i.forEach(function(n){t.removeEventListener(n.trim(),e,!1)})}function E(t){return t}function A(t,n,e,i,o){return i*(n/=o)*n+e}function T(t,n,e,i,o){return-i*(n/=o)*(n-2)+e}function z(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n+e:-i/2*(--n*(n-2)-1)+e}function M(t,n,e,i,o){return i*(n/=o)*n*n+e}function D(t,n,e,i,o){return i*((n=n/o-1)*n*n+1)+e}function Q(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n*n+e:i/2*((n-=2)*n*n+2)+e}function j(t,n,e,i,o){return i*(n/=o)*n*n*n+e}function B(t,n,e,i,o){return-i*((n=n/o-1)*n*n*n-1)+e}function P(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n*n*n+e:-i/2*((n-=2)*n*n*n-2)+e}function R(t,n,e,i,o){return i*(n/=o)*n*n*n*n+e}function H(t,n,e,i,o){return i*((n=n/o-1)*n*n*n*n+1)+e}function W(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n*n*n*n+e:i/2*((n-=2)*n*n*n*n+2)+e}function q(t,n,e,i,o){return-i*ut(n/o*(pt/2))+i+e}function F(t,n,e,i,o){return i*at(n/o*(pt/2))+e}function U(t,n,e,i,o){return-i/2*(ut(pt*n/o)-1)+e}function $(t,n,e,i,o){return 0===n?e:i*ct(2,10*(n/o-1))+e}function N(t,n,e,i,o){return n===o?e+i:i*(-ct(2,-10*n/o)+1)+e}function X(t,n,e,i,o){return 0===n?e:n===o?e+i:(n/=o/2)<1?i/2*ct(2,10*(n-1))+e:i/2*(-ct(2,-10*--n)+2)+e}function Y(t,n,e,i,o){return-i*(ft(1-(n/=o)*n)-1)+e}function J(t,n,e,i,o){return i*ft(1-(n=n/o-1)*n)+e}function V(t,n,e,i,o){return(n/=o/2)<1?-i/2*(ft(1-n*n)-1)+e:i/2*(ft(1-(n-=2)*n)+1)+e}function G(t,n,e,i,o){var r=1.70158,l=0,u=i;return 0===n?e:1===(n/=o)?e+i:(l||(l=.3*o),u<st(i)?(u=i,r=l/4):r=l/(2*pt)*ht(i/u),-(u*ct(2,10*(n-=1))*at((n*o-r)*(2*pt)/l))+e)}function K(t,n,e,i,o){var r=1.70158,l=0,u=i;return 0===n?e:1===(n/=o)?e+i:(l||(l=.3*o),u<st(i)?(u=i,r=l/4):r=l/(2*pt)*ht(i/u),u*ct(2,-10*n)*at((n*o-r)*(2*pt)/l)+i+e)}function Z(t,n,e,i,o){var r=1.70158,l=0,u=i;return 0===n?e:2===(n/=o/2)?e+i:(l||(l=o*(.3*1.5)),u<st(i)?(u=i,r=l/4):r=l/(2*pt)*ht(i/u),1>n?-.5*(u*ct(2,10*(n-=1))*at((n*o-r)*(2*pt)/l))+e:u*ct(2,-10*(n-=1))*at((n*o-r)*(2*pt)/l)*.5+i+e)}function tt(t,n,e,i,o){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return i*(n/=o)*n*((r+1)*n-r)+e}function nt(t,n,e,i,o){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return i*((n=n/o-1)*n*((r+1)*n+r)+1)+e}function et(t,n,e,i,o){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return(n/=o/2)<1?i/2*(n*n*(((r*=1.525)+1)*n-r))+e:i/2*((n-=2)*n*(((r*=1.525)+1)*n+r)+2)+e}function it(t,n,e,i,o){return(n/=o)<1/2.75?i*(7.5625*n*n)+e:2/2.75>n?i*(7.5625*(n-=1.5/2.75)*n+.75)+e:2.5/2.75>n?i*(7.5625*(n-=2.25/2.75)*n+.9375)+e:i*(7.5625*(n-=2.625/2.75)*n+.984375)+e}function ot(t,n,e,i,o){return i-it(t,o-n,0,i,o)+e}function rt(t,n,e,i,o){return o/2>n?.5*ot(t,2*n,0,i,o)+e:.5*it(t,2*n-o,0,i,o)+.5*i+e}var lt={};lt["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},lt.classCallCheck=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")},lt.createClass=function(){function t(t,n){for(var e=0;e<n.length;e++){var i=n[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(n,e,i){return e&&t(n.prototype,e),i&&t(n,i),n}}();var ut=Math.cos,at=Math.sin,ct=Math.pow,st=Math.abs,ft=Math.sqrt,ht=Math.asin,pt=Math.PI,dt=Math.max,vt=Math.min,gt=Math.round,yt=ct(2,53)-1,St=["Boolean","Number","String","Function","Array","Object"],mt={};St.forEach(function(t){mt["[object "+t+"]"]=t.toLowerCase()});for(var Ct=window,kt=document,bt={y:"scrollTop",x:"scrollLeft"},wt={y:"pageYOffset",x:"pageXOffset"},Ot=(function(){var t=navigator.userAgent;return-1===t.indexOf("Android 2.")&&-1===t.indexOf("Android 4.0")||-1===t.indexOf("Mobile Safari")||-1!==t.indexOf("Chrome")||-1!==t.indexOf("Windows Phone")?window.history&&"pushState"in window.history&&"file:"!==window.location.protocol:!1}()),_t=Object.freeze({linear:E,InQuad:A,OutQuad:T,InOutQuad:z,InCubic:M,OutCubic:D,InOutCubic:Q,InQuart:j,OutQuart:B,InOutQuart:P,InQuint:R,OutQuint:H,InOutQuint:W,InSine:q,OutSine:F,InOutSine:U,InExpo:$,OutExpo:N,InOutExpo:X,InCirc:Y,OutCirc:J,InOutCirc:V,InElastic:G,OutElastic:K,InOutElastic:Z,InBack:tt,OutBack:nt,InOutBack:et,OutBounce:it,InBounce:ot,InOutBounce:rt}),It=["ms","moz","webkit"],xt=0,Lt=Ct.requestAnimationFrame,Et=Ct.cancelAnimationFrame,At=0;At<It.length&&!Lt;++At)Lt=Ct[It[At]+"RequestAnimationFrame"],Et=Ct[It[At]+"CancelAnimationFrame"]||Ct[It[At]+"CancelRequestAnimationFrame"];Lt||(Lt=function(t){var n=Date.now(),e=dt(0,16-(n-xt)),i=setTimeout(function(){t(n+e)},e);return xt=n+e,i}),Et||(Et=function(t){clearTimeout(t)});var Tt=function(){function t(n){lt.classCallCheck(this,t),this.el=n,this.props={},this.options={},this.progress=!1,this.easing=null,this.startTime=null,this.rafId=null}return lt.createClass(t,[{key:"run",value:function(t,n,e){var o=this;this.progress||(this.props={x:t,y:n},this.options=e,this.easing=i(e.easing)?e.easing:_t[e.easing.replace("ease","")],this.progress=!0,setTimeout(function(){o.startProps={x:O(o.el,"x"),y:O(o.el,"y")},o.rafId=Lt(function(t){return o._loop(t)})},this.options.delay))}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!0:arguments[0],n=this.options.complete;this.startTime=null,this.progress=!1,Et(this.rafId),t&&(_(this.el,this.props.x,"x"),_(this.el,this.props.y,"y")),i(n)&&(n.call(this),this.options.complete=null)}},{key:"_loop",value:function(t){var n=this;if(this.startTime||(this.startTime=t),!this.progress)return void this.stop(!1);var e=this.el,i=this.props,o=this.options,r=this.startTime,l=this.startProps,u=this.easing,a=o.duration,s=o.step,f={},h=t-r,p=vt(1,dt(h/a,0));c(i,function(t,n){var e=l[n],i=t-e;if(0===i)return!0;var o=u(p,a*p,0,1,a);f[n]=gt(e+i*o)}),c(f,function(t,n){_(e,t,n)}),a>=h?(s.call(this,p,f),this.rafId=Lt(function(t){return n._loop(t)})):this.stop(!0)}}]),t}(),zt=function(){return"onwheel"in kt?"wheel":"onmousewheel"in kt?"mousewheel":"DOMMouseScroll"}(),Mt=zt+", touchstart, touchmove",Dt="DOMContentLoaded",Qt=!1;x(kt,Dt,function(){Qt=!0});var jt=function(){function t(){var n=this,e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],i=arguments.length<=1||void 0===arguments[1]?"body, html":arguments[1];lt.classCallCheck(this,t);var o=s({},t.defaults,e);this.options=o,this.getContainer(i,function(t){n.container=t,n.header=h(o.header),n.tween=new Tt(t),n._trigger=null,n._shouldCallCancelScroll=!1,n.bindContainerClick(),n.hook(o,"initialized")})}return lt.createClass(t,[{key:"to",value:function(t){var n=this,i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],o=this.container,r=this.header,l=s({},this.options,i);this._options=l;var u=this.parseCoodinate(l.offset),a=this._trigger,c=this.parseCoodinate(t),f=null;if(this._trigger=null,this._shouldCallCancelScroll=!1,this.stop(),o){if(!c&&e(t))if(f=/^#/.test(t)?t:null,"#"===t)c={top:0,left:0};else{var p=h(t),d=I(p,o);if(!d)return;c=d}if(c){u&&(c.top+=u.top,c.left+=u.left),r&&(c.top=dt(0,c.top-k(r).height));var v=w(o),g=v.viewport,y=v.size;this.hook(l,"beforeScroll",c,a)!==!1&&(c.top=l.verticalScroll?dt(0,vt(y.height-g.height,c.top)):O(o,"y"),c.left=l.horizontalScroll?dt(0,vt(y.width-g.width,c.left)):O(o,"x"),this.tween.run(c.left,c.top,{duration:l.duration,delay:l.delay,easing:l.easing,complete:function(){null!=f&&f!==window.location.hash&&n.updateURLHash(f,l.updateURL),n.unbindContainerStop(),n._options=null,n._shouldCallCancelScroll?n.hook(l,"cancelScroll"):n.hook(l,"afterScroll",c,a),n.hook(l,"completeScroll",n._shouldCallCancelScroll)},step:function(t,e){n.hook(l,"stepScroll",t,e)}}),this.bindContainerStop())}}}},{key:"toTop",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,s({},n,{verticalScroll:!0,horizontalScroll:!1}))}},{key:"toLeft",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,s({},n,{verticalScroll:!1,horizontalScroll:!0}))}},{key:"toElement",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(t instanceof Element){var e=I(t,this.container);this.to(e,s({},n))}}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];this._stopScrollListener&&(this._shouldCallCancelScroll=!0),this.tween.stop(t)}},{key:"update",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];this.stop(),this.unbindContainerClick(),this.unbindContainerStop(),this.options=s({},this.options,t),this.header=h(this.options.header),this.bindContainerClick()}},{key:"destroy",value:function(){this.stop(),this.unbindContainerClick(),this.unbindContainerStop(),this.container=null,this.header=null,this.tween=null}},{key:"initialized",value:function(){}},{key:"beforeScroll",value:function(t,n){return!0}},{key:"cancelScroll",value:function(){}},{key:"afterScroll",value:function(t,n){}},{key:"completeScroll",value:function(t){}},{key:"stepScroll",value:function(t,n){}},{key:"parseCoodinate",value:function(t){var n=this._options?this._options.verticalScroll:this.options.verticalScroll,i={top:0,left:0};if(a(t,"top")||a(t,"left"))i=s(i,t);else if(o(t))2===t.length?(i.top=t[0],i.left=t[1]):(i.top=n?t[0]:0,i.left=n?0:t[0]);else if(l(t))i.top=n?t:0,i.left=n?0:t;else{if(!e(t))return null;var r=f(t);if(/^\d+,\d+$/.test(r))r=r.split(","),i.top=r[0],i.left=r[1];else if(/^(top|left):\d+,?(?:(top|left):\d+)?$/.test(r)){var u=r.match(/top:(\d+)/),c=r.match(/left:(\d+)/);i.top=u?u[1]:0,i.left=c?c[1]:0}else{if(!this.container||!/^(\+|-)=(\d+)$/.test(r))return null;var h=O(this.container,n?"y":"x"),p=r.match(/^(\+|-)=(\d+)$/),d=p[1],v=parseInt(p[2],10);"+"===d?(i.top=n?h+v:0,i.left=n?0:h+v):(i.top=n?h-v:0,i.left=n?0:h-v)}}return i.top=parseInt(i.top,10),i.left=parseInt(i.left,10),i}},{key:"updateURLHash",value:function(t,n){Ot&&n&&window.history["replace"===n?"replaceState":"pushState"](null,null,t)}},{key:"getContainer",value:function(t,n){var e=this,i=this.options,o=i.verticalScroll,r=i.horizontalScroll,l=null;o&&(l=y(t,"y")),!l&&r&&(l=y(t,"x")),l||Qt?n.call(this,l):!function(){var i=!1;x(kt,Dt,function(){i=!0,e.getContainer(t,n)}),x(Ct,"load",function(){i||e.getContainer(t,n)})}()}},{key:"bindContainerClick",value:function(){var t=this.container;t&&(this._containerClickListener=this.handleContainerClick.bind(this),x(t,"click",this._containerClickListener))}},{key:"unbindContainerClick",value:function(){var t=this.container;t&&this._containerClickListener&&(L(t,"click",this._containerClickListener),this._containerClickListener=null)}},{key:"bindContainerStop",value:function(){var t=this.container;t&&(this._stopScrollListener=this.handleStopScroll.bind(this),x(t,Mt,this._stopScrollListener))}},{key:"unbindContainerStop",value:function(){var t=this.container;t&&this._stopScrollListener&&(L(t,Mt,this._stopScrollListener),this._stopScrollListener=null)}},{key:"hook",value:function(t,n){for(var e=t[n],o=arguments.length,r=Array(o>2?o-2:0),l=2;o>l;l++)r[l-2]=arguments[l];if(i(e)){var u=e.apply(this,r);if("undefined"==typeof u)return u}return this[n].apply(this,r)}},{key:"handleStopScroll",value:function(t){var n=this._options?this._options.stopScroll:this.options.stopScroll;n?this.stop():t.preventDefault()}},{key:"handleContainerClick",value:function(t){for(var n=this.options,e=t.target;e&&e!==kt;e=e.parentNode)if(d(e,n.trigger)){var i=e.getAttribute("data-scroll"),o=this.parseDataOptions(e),r=i||e.getAttribute("href");n=s({},n,o),n.preventDefault&&t.preventDefault(),n.stopPropagation&&t.stopPropagation(),this._trigger=e,n.horizontalScroll&&n.verticalScroll?this.to(r,n):n.verticalScroll?this.toTop(r,n):n.horizontalScroll&&this.toLeft(r,n)}}},{key:"parseDataOptions",value:function(t){var n=t.getAttribute("data-scroll-options");return n?JSON.parse(n):{}}}]),t}();return jt.defaults={trigger:"[data-scroll]",header:"[data-scroll-header]",duration:1e3,delay:0,easing:"easeOutQuint",offset:0,verticalScroll:!0,horizontalScroll:!1,stopScroll:!0,updateURL:!1,preventDefault:!0,stopPropagation:!0,initialized:null,beforeScroll:null,afterScroll:null,cancelScroll:null,completeScroll:null,stepScroll:null},jt}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
69958
29
1150
0
542