Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
adding undefined checker
Browse files Browse the repository at this point in the history
  • Loading branch information
bento-n-box committed Feb 7, 2017
1 parent c3caec7 commit 8db8b7a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion dist/inview.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function getBoundingBox(el) {
}

// Checks to see if element is visisble

function isElementFullyVisible(el, rect, viewport) {
return rect.top >= viewport.top && rect.left >= 0 && rect.bottom <= viewport.top + viewport.height && rect.right <= (window.innerWidth || document.documentElement.clientWidth);
}
Expand Down Expand Up @@ -110,6 +109,10 @@ var ReactInviewWrapper = function ReactInviewWrapper() {
}, {
key: 'handleScroll',
value: function handleScroll() {
if (typeof this.refs.container === 'undefined') {
return;
}

var element = this.refs.container.children[0];
var boundingBox = getBoundingBox(element);
var viewPortBox = getViewPortBox(offsetY, boundingBox);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Benton Rochester",
"name": "react-inview-js",
"version": "1.2.6",
"version": "1.2.7",
"description": "React Inview checker with only javascript",
"main": "dist/index.js",
"standard": {
Expand Down
4 changes: 2 additions & 2 deletions src/inview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ function getBoundingBox(el) {
}

// Checks to see if element is visisble

function isElementFullyVisible (el, rect, viewport) {
return (
rect.top >= viewport.top &&
Expand All @@ -39,7 +38,6 @@ function isElementFullyVisible (el, rect, viewport) {
);
}


function isElementTopVisible (el, rect, viewport) {
const topIsInView = !(rect.top >= (viewport.top + viewport.height));
const topIsAboveView = !((rect.top + rect.height - viewport.height) <= viewport.top);
Expand Down Expand Up @@ -87,6 +85,8 @@ let ReactInviewWrapper = function ReactInviewWrapper ({
}

handleScroll() {
if (typeof this.refs.container === 'undefined') { return; }

const element = this.refs.container.children[0];
const boundingBox = getBoundingBox(element);
const viewPortBox = getViewPortBox(offsetY, boundingBox);
Expand Down

0 comments on commit 8db8b7a

Please sign in to comment.