From 120a795e3efcc5f9f62202192e072014712577e6 Mon Sep 17 00:00:00 2001 From: Robert Reinhard Date: Mon, 24 Sep 2018 14:40:14 -0700 Subject: [PATCH 1/3] Adding a callback type of handler --- index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/index.js b/index.js index a53406d..d4a83e2 100644 --- a/index.js +++ b/index.js @@ -58,6 +58,15 @@ return getNumber(easing, start, end, ratio); } + function CallbackParallax (element, callback) { + this.element = element; + this.callback = callback; + } + + CallbackParallax.prototype.handleScroll = function (ratio, distance) { + this.callback(ratio, distance) + }; + function OptionsParallax (element, options, container) { container = container || scrollMonitor; this.options = options; @@ -144,6 +153,8 @@ var newItem; if (typeof optionsOrSpeed === 'number') { newItem = new SpeedParallax(element, optionsOrSpeed); + } else if (typeof optionsOrSpeed === 'function') { + newItem = new CallbackParallax(element, optionsOrSpeed); } else { newItem = new OptionsParallax(element, optionsOrSpeed, this.container); } From dbffc354d9515d51719c07f2793d73d03c3d8c4b Mon Sep 17 00:00:00 2001 From: Robert Reinhard Date: Mon, 24 Sep 2018 14:42:33 -0700 Subject: [PATCH 2/3] Adding a destroy option --- index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.js b/index.js index d4a83e2..16dadbf 100644 --- a/index.js +++ b/index.js @@ -161,6 +161,13 @@ this.items.push(newItem); }; + + Root.prototype.destroy = function () { + if (this.watcher) { + this.items = [] + this.watcher.destroy() + } + } return { create: function (item, offsets, container) { From 8b1cf756f0eca08983ba4f23fe0e5ffc9fad1233 Mon Sep 17 00:00:00 2001 From: Robert Reinhard Date: Tue, 25 Sep 2018 08:19:03 -0700 Subject: [PATCH 3/3] Add the watcher to the callback --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 16dadbf..9faa149 100644 --- a/index.js +++ b/index.js @@ -63,8 +63,8 @@ this.callback = callback; } - CallbackParallax.prototype.handleScroll = function (ratio, distance) { - this.callback(ratio, distance) + CallbackParallax.prototype.handleScroll = function (ratio, distance, watcher) { + this.callback(ratio, distance, watcher) }; function OptionsParallax (element, options, container) {