scrollwatch
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "scrollwatch", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"author": "Evan Dull <evandull@gmail.com>", | ||
"description": "Easily add lazy loading, infinite scrolling, or any other dynamic interaction based on scroll position (with no dependencies).", | ||
"main": "./dist/ScrollWatch-1.0.0.min.js", | ||
"main": "./dist/ScrollWatch-1.1.0.min.js", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -18,2 +18,6 @@ 'use strict'; | ||
inViewClass: 'scroll-watch-in-view', | ||
debounce: false, | ||
debounceTriggerLeading: false, | ||
scrollDebounce: 250, | ||
resizeDebounce: 250, | ||
scrollThrottle: 250, | ||
@@ -103,2 +107,66 @@ resizeThrottle: 250, | ||
// http://underscorejs.org/#debounce | ||
var debounce = function(func, wait, immediate) { | ||
var timeout; | ||
var args; | ||
var context; | ||
var timestamp; | ||
var result; | ||
var later = function() { | ||
var last = new Date().getTime() - timestamp; | ||
if (last < wait && last >= 0) { | ||
timeout = setTimeout(later, wait - last); | ||
} else { | ||
timeout = null; | ||
if (!immediate) { | ||
result = func.apply(context, args); | ||
if (!timeout) { | ||
context = args = null; | ||
} | ||
} | ||
} | ||
}; | ||
return function() { | ||
var callNow = immediate && !timeout; | ||
context = this; | ||
args = arguments; | ||
timestamp = new Date().getTime(); | ||
if (!timeout) { | ||
timeout = setTimeout(later, wait); | ||
} | ||
if (callNow) { | ||
result = func.apply(context, args); | ||
context = args = null; | ||
} | ||
return result; | ||
}; | ||
}; | ||
// Get the scrolling container element to watch if it's not the default window/documentElement. | ||
@@ -517,5 +585,14 @@ var saveContainerElement = function() { | ||
// to 'this', give each instance it's own event handler. | ||
data.scrollHandler = throttle(handler.bind(this), data.config.scrollThrottle, this); | ||
data.resizeHandler = throttle(handler.bind(this), data.config.resizeThrottle, this); | ||
if (data.config.debounce) { | ||
data.scrollHandler = debounce(handler.bind(this), data.config.scrollDebounce, data.config.debounceTriggerLeading); | ||
data.resizeHandler = debounce(handler.bind(this), data.config.resizeDebounce, data.config.debounceTriggerLeading); | ||
} else { | ||
data.scrollHandler = throttle(handler.bind(this), data.config.scrollThrottle, this); | ||
data.resizeHandler = throttle(handler.bind(this), data.config.resizeThrottle, this); | ||
} | ||
saveContainerElement.call(this); | ||
@@ -522,0 +599,0 @@ addListeners.call(this); |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
62855
14
875
1