Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

Commit

Permalink
Merge branch 'anzzstuff-favor-last'
Browse files Browse the repository at this point in the history
  • Loading branch information
makotot committed Jul 29, 2016
2 parents 055c464 + 5234c9a commit bda344f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/js/lib/Scrollspy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ export class Scrollspy extends React.Component {
elemsOutView.push(currentContent)
}

const isLastItem = i === max - 1
const isScrolled = (document.documentElement.scrollTop || document.body.scrollTop) > 0

// https://github.com/makotot/react-scrollspy/pull/26#issue-167413769
if (this._isAtBottom() && this._isInView(currentContent) && !isInView && isLastItem && iscrolled) {
elemsOutView.pop()
elemsOutView.push(...elemsInView)
elemsInView = [currentContent]
viewStatusList.fill(false)
isInView = true
}

viewStatusList.push(isInView)
}

Expand All @@ -79,6 +91,15 @@ export class Scrollspy extends React.Component {
return (elTop < scrollBottom) && (elBottom > scrollTop)
}

_isAtBottom () {
const doc = document
const body = doc.body
const scrollTop = (doc.documentElement && doc.documentElement.scrollTop) || body.scrollTop
const scrollHeight = (doc.documentElement && doc.documentElement.scrollHeight) || body.scrollHeight
const scrolledToBottom = (scrollTop + window.innerHeight) >= scrollHeight

return scrolledToBottom
}
_spy (targets) {
this.setState({
inViewState: this._getElemsViewState(targets).viewStatusList,
Expand Down

0 comments on commit bda344f

Please sign in to comment.