Comparing version 2.0.0 to 2.1.0
@@ -168,2 +168,3 @@ /** | ||
this.onBottom = opts.onBottom; | ||
this.onMaximized = opts.onMaximized; | ||
this._wasTop = true; | ||
@@ -179,2 +180,3 @@ this._wasBottom = false; | ||
onTop = this.onTop, | ||
onMaximized = this.onMaximized, | ||
_wasTop = this._wasTop, | ||
@@ -191,11 +193,18 @@ _wasBottom = this._wasBottom, | ||
var atBottom = scrollHeight > height && height + y + offset >= scrollHeight; | ||
var untriggered = false; | ||
if (onBottom && !_wasBottom && atBottom) { | ||
onBottom.call(this, container, viewportState); | ||
once && this.destroy(); | ||
} else if (onTop && !_wasTop && atTop) { | ||
onTop.call(this, container, viewportState); | ||
once && this.destroy(); | ||
} else if (onMaximized && scrollHeight === height) { | ||
onMaximized.call(this, container, viewportState); | ||
} else { | ||
untriggered = true; | ||
} | ||
if (once && !untriggered) { | ||
this.destroy(); | ||
} | ||
this._wasTop = atTop; | ||
@@ -202,0 +211,0 @@ this._wasBottom = atBottom; |
@@ -174,2 +174,3 @@ (function (global, factory) { | ||
this.onBottom = opts.onBottom; | ||
this.onMaximized = opts.onMaximized; | ||
this._wasTop = true; | ||
@@ -185,2 +186,3 @@ this._wasBottom = false; | ||
onTop = this.onTop, | ||
onMaximized = this.onMaximized, | ||
_wasTop = this._wasTop, | ||
@@ -197,11 +199,18 @@ _wasBottom = this._wasBottom, | ||
var atBottom = scrollHeight > height && height + y + offset >= scrollHeight; | ||
var untriggered = false; | ||
if (onBottom && !_wasBottom && atBottom) { | ||
onBottom.call(this, container, viewportState); | ||
once && this.destroy(); | ||
} else if (onTop && !_wasTop && atTop) { | ||
onTop.call(this, container, viewportState); | ||
once && this.destroy(); | ||
} else if (onMaximized && scrollHeight === height) { | ||
onMaximized.call(this, container, viewportState); | ||
} else { | ||
untriggered = true; | ||
} | ||
if (once && !untriggered) { | ||
this.destroy(); | ||
} | ||
this._wasTop = atTop; | ||
@@ -208,0 +217,0 @@ this._wasBottom = atBottom; |
{ | ||
"name": "viewprt", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "tiny, high performance viewport position & intersection observer", | ||
@@ -25,3 +25,3 @@ "author": "Garth Poitras <garth22@gmail.com>", | ||
"type": "git", | ||
"url": "git+https://github.com/gdub22/viewprt.git" | ||
"url": "git+https://github.com/gpoitch/viewprt.git" | ||
}, | ||
@@ -28,0 +28,0 @@ "scripts": { |
@@ -1,6 +0,6 @@ | ||
# viewprt [![Build Status](https://travis-ci.org/gdub22/viewprt.svg)](https://travis-ci.org/gdub22/viewprt) | ||
# viewprt [![Build Status](https://travis-ci.org/gpoitch/viewprt.svg)](https://travis-ci.org/gpoitch/viewprt) | ||
A tiny, high performance viewport position & intersection observation tool. You can watch when elements enter & exit the viewport, or when the viewport itself is at the bottom or top. Use this as a building block for things such as lazy loaders, infinite scrollers, etc. | ||
#### [Demo](https://rawgit.com/gdub22/viewprt/master/demos/index.html) | ||
#### [Demo](https://rawgit.com/gpoitch/viewprt/master/demos/index.html) | ||
#### [Dist](https://unpkg.com/viewprt/dist/) | ||
@@ -34,7 +34,8 @@ | ||
// options (defaults) | ||
container: document.body, // the viewport container element | ||
offset: 0, // offset from the edge of the viewport in pixels | ||
once: false, // if true, observer is detroyed after first callback is triggered | ||
onBottom (container, viewportState) {}, // callback when the viewport reaches the bottom | ||
onTop (container, viewportState) {} // callback when the viewport reaches the top | ||
container: document.body, // the viewport container element | ||
offset: 0, // offset from the edge of the viewport in pixels | ||
once: false, // if true, observer is detroyed after first callback is triggered | ||
onBottom (container, viewportState) {}, // callback when the viewport reaches the bottom | ||
onTop (container, viewportState) {}, // callback when the viewport reaches the top | ||
onMaximized (container, viewportState) {} // callback when the viewport and container are the same size | ||
}) | ||
@@ -41,0 +42,0 @@ |
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
19122
450
60