Skip to content
Permalink
Browse files

fix: force:false to correctly check element visibility in viewport (#150

)

* Fix viewport issue for force:false

* Defensively call onDone for force:false
  • Loading branch information...
brophdawg11 authored and rigor789 committed Sep 10, 2019
1 parent 208ebf5 commit 14eb022c07351e17740a0922a08029075ae4d115
Showing with 9 additions and 2 deletions.
  1. +9 −2 src/scrollTo.js
@@ -187,8 +187,15 @@ export const scroller = () => {
diffX = targetX - initialX;

if (!force) {
// When the container is the default (body) we need to use the viewport
// height, not the entire body height
const containerHeight =
container.tagName.toLowerCase() === "body"
? document.documentElement.clientHeight ||
window.innerHeight
: container.offsetHeight;
const containerTop = initialY;
const containerBottom = containerTop + container.offsetHeight;
const containerBottom = containerTop + containerHeight;
const elementTop = targetY;
const elementBottom = elementTop + element.offsetHeight;
if (
@@ -197,7 +204,7 @@ export const scroller = () => {
) {
// make sure to call the onDone callback even if there is no need to
// scroll the container. Fixes #111 (ref #118)
onDone(element);
if (onDone) onDone(element);
return;
}
}

0 comments on commit 14eb022

Please sign in to comment.
You can’t perform that action at this time.