Skip to content

Instantly share code, notes, and snippets.

@samg11
Created April 12, 2021 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samg11/5a99bd1abafe9900801f42e63e791e74 to your computer and use it in GitHub Desktop.
Save samg11/5a99bd1abafe9900801f42e63e791e74 to your computer and use it in GitHub Desktop.
Chatre: get distance from bottom of scroll with jquery. Should console log distance from bottom when scrolling.
let scrollBarHeight;
// ONLY RUN WHEN SCROLLED TO BOTTOM
window.scrollBarHeight = (document.querySelector("#messages").scrollHeight) - ($("#messages").height() + $("#messages").scrollTop());
// END OF ONLY RUN WHEN SCROLLED TO BOTTOM
$("#messages").scroll(() => {
const a = document.querySelector("#messages").scrollHeight;
const b = $("#messages").height() * 2;
const c = $("#messages").height() - $("#messages").scrollTop();
const d = window.scrollBarHeight;
console.log(a - b + c - d);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment