Use range for userIsScrolling in case scrollTop is still working

Co-authored-by: Stamates <stamates@hotmail.com>
pull/769/head
jimmay5469 6 years ago
parent 1e236ce2a3
commit 66eee235b4
  1. 10
      apps/block_scout_web/assets/js/utils.js

@ -46,17 +46,19 @@ export function prependWithClingBottom ($el, content) {
} }
$el.on('animationstart', setIsAnimating) $el.on('animationstart', setIsAnimating)
let expectedScrollPosition = window.scrollY let startingScrollPosition = window.scrollY
let endingScrollPosition = window.scrollY
function userIsScrolling () { function userIsScrolling () {
return expectedScrollPosition !== window.scrollY return window.scrollY < startingScrollPosition || endingScrollPosition < window.scrollY
} }
const clingDistanceFromBottom = document.body.scrollHeight - window.scrollY const clingDistanceFromBottom = document.body.scrollHeight - window.scrollY
let clingBottomLoop = window.requestAnimationFrame(function clingBottom () { let clingBottomLoop = window.requestAnimationFrame(function clingBottom () {
if (userIsScrolling()) return stopClinging() if (userIsScrolling()) return stopClinging()
expectedScrollPosition = document.body.scrollHeight - clingDistanceFromBottom startingScrollPosition = window.scrollY
$(window).scrollTop(expectedScrollPosition) endingScrollPosition = document.body.scrollHeight - clingDistanceFromBottom
$(window).scrollTop(endingScrollPosition)
clingBottomLoop = window.requestAnimationFrame(clingBottom) clingBottomLoop = window.requestAnimationFrame(clingBottom)
}) })

Loading…
Cancel
Save