Check if a user has scrolled to the bottom (not just the window, but any element)
Use the .scroll()
event on window
, like this:
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
alert("bottom!");
}
});
You can test it here, this takes the top scroll of the window, so how much it's scrolled down, adds the height of the visible window and checks if that equals the height of the overall content (document
). If you wanted to instead check if the user is near the bottom, it'd look something like this:
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
alert("near bottom!");
}
});
You can test that version here, just adjust that 100
to whatever pixel from the bottom you want to trigger on.
Check if a user has scrolled to the bottom (not just the window, but any element)
Use the .scroll()
event on window
, like this:
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
alert("bottom!");
}
});
You can test it here, this takes the top scroll of the window, so how much it's scrolled down, adds the height of the visible window and checks if that equals the height of the overall content (document
). If you wanted to instead check if the user is near the bottom, it'd look something like this:
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
alert("near bottom!");
}
});
You can test that version here, just adjust that 100
to whatever pixel from the bottom you want to trigger on.
How to detect if browser window is scrolled to bottom?
window.onscroll = function(ev) {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
// you're at the bottom of the page
}
};
See demo
Check if user scroll to bottom of the page work opposite
please try this one
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
alert("bottom!");
}
});
you can also have another option on the following question:
Check if a user has scrolled to the bottom
Check if a user has scrolled to the bottom in subpixel precision era
My current solution:
function isContentScrolledToBottom(element) {
const rest = element.scrollHeight - element.scrollTop;
return Math.abs(element.clientHeight - rest) < 1;
}
It checks if element is scrolled to bottom with ±1 accuracy.
Detecting when user scrolls to bottom of div with React js
you can use el.getBoundingClientRect().bottom
to check if the bottom has been viewed
isBottom(el) {
return el.getBoundingClientRect().bottom <= window.innerHeight;
}
componentDidMount() {
document.addEventListener('scroll', this.trackScrolling);
}
componentWillUnmount() {
document.removeEventListener('scroll', this.trackScrolling);
}
trackScrolling = () => {
const wrappedElement = document.getElementById('header');
if (this.isBottom(wrappedElement)) {
console.log('header bottom reached');
document.removeEventListener('scroll', this.trackScrolling);
}
};
Check if a user has scrolled to the bottom (not just the window, but any element)
Use the .scroll()
event on window
, like this:
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
alert("bottom!");
}
});
You can test it here, this takes the top scroll of the window, so how much it's scrolled down, adds the height of the visible window and checks if that equals the height of the overall content (document
). If you wanted to instead check if the user is near the bottom, it'd look something like this:
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
alert("near bottom!");
}
});
You can test that version here, just adjust that 100
to whatever pixel from the bottom you want to trigger on.
Check if user scroll to bottom of the page work opposite
please try this one
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
alert("bottom!");
}
});
you can also have another option on the following question:
Check if a user has scrolled to the bottom
Related Topics
What Is the 'New' Keyword in JavaScript
Why Is Setstate in Reactjs Async Instead of Sync
Generate Random String/Characters in JavaScript
Weird Behavior With Objects & Console.Log
JavaScript by Reference Vs. by Value
How to Pad a Value With Leading Zeros
Http Get Request in JavaScript
Onclick or Inline Script Isn't Working in Extension
How to Detect If a Browser Window Is Not Currently Active
How to Return Many Promises and Wait For Them All Before Doing Other Stuff
What Is the Purpose of a Self Executing Function in JavaScript
Sorting in JavaScript: Shouldn't Returning a Boolean Be Enough For a Comparison Function
How to Reload a Page Using JavaScript
What Does 'Return' Keyword Mean Inside 'Foreach' Function
Firebase Kicks Out Current User
How to Omit Parentheses When Creating an Object Using the "New" Operator