Welcome to mirror list, hosted at ThFree Co, Russian Federation.

scroll_utils.js « utils « lib « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bab84448657ff00ac39682bcccc5c36ed93c7584 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
 *  @returns {Boolean}
 */
export const isScrolledToBottom = () => {
  // Use clientHeight to account for any horizontal scrollbar.
  const { scrollHeight, scrollTop, clientHeight } = document.documentElement;

  // scrollTop can be a float, so round up to next integer.
  return Math.ceil(scrollTop + clientHeight) >= scrollHeight;
};

/**
 * Checks if page is scrolled to the top
 * @returns {Boolean}
 */
export const isScrolledToTop = () => $(document).scrollTop() === 0;

export const scrollDown = () => {
  const $document = $(document);
  $document.scrollTop($document.height());
};

export const scrollUp = () => {
  $(document).scrollTop(0);
};