Search code examples
javascriptandroidgoogle-chromeinfinite-scroll

javascript code is not working latest chrome in android


element.scrollHeight - element.scrollTop === element.clientHeight

This is not working in latest chrome version in android ,I tested in firefox ,safari(both mobile devices and pc) and even pc chrome is working,i could not figure out why is it not working in android chome. https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight


Solution

  • I struggled with this issue for a while and just figured out by debugging my phone connected to my computer. On desktop and iOS browsers everything works as expected but on Android Chrome exclusively element.scollTop is calculated in insane fractions. i.e 42.81747128182.

    Because of this on Android element.scrollHeight - element.scrollTop === element.clientHeight will not work.

    Simply rounding off that decimal does this trick. Try:

    element.scrollHeight - Math.floor(element.scrollTop) === element.clientHeight