2018-11-08 19:23:39 +05:30
|
|
|
import $ from 'jquery';
|
|
|
|
|
|
|
|
export const canScroll = () => $(document).height() > $(window).height();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the entire page is scrolled down all the way to the bottom
|
2018-12-05 23:21:45 +05:30
|
|
|
* @returns {Boolean}
|
2018-11-08 19:23:39 +05:30
|
|
|
*/
|
|
|
|
export const isScrolledToBottom = () => {
|
2023-04-23 21:23:45 +05:30
|
|
|
// Use clientHeight to account for any horizontal scrollbar.
|
|
|
|
const { scrollHeight, scrollTop, clientHeight } = document.documentElement;
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
// scrollTop can be a float, so round up to next integer.
|
|
|
|
return Math.ceil(scrollTop + clientHeight) >= scrollHeight;
|
2018-11-08 19:23:39 +05:30
|
|
|
};
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
/**
|
|
|
|
* Checks if page is scrolled to the top
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
export const isScrolledToTop = () => $(document).scrollTop() === 0;
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
export const scrollDown = () => {
|
|
|
|
const $document = $(document);
|
|
|
|
$document.scrollTop($document.height());
|
|
|
|
};
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
export const scrollUp = () => {
|
|
|
|
$(document).scrollTop(0);
|
|
|
|
};
|