diff options
author | Phil Hughes <me@iamphill.com> | 2017-07-27 15:53:04 +0100 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-08-03 17:03:49 +0100 |
commit | b507682d6e799f737c05f27201dc4a0dbe3aba1d (patch) | |
tree | b8a597d6bd605a4a858952e913627dd9c86eb338 /app/assets/javascripts/lib/utils/sticky.js | |
parent | 655510ec9a658c28f50ccb0caea394f5db7cae59 (diff) | |
download | gitlab-ce-b507682d6e799f737c05f27201dc4a0dbe3aba1d.tar.gz |
made the changed files holder sticky
Diffstat (limited to 'app/assets/javascripts/lib/utils/sticky.js')
-rw-r--r-- | app/assets/javascripts/lib/utils/sticky.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/app/assets/javascripts/lib/utils/sticky.js b/app/assets/javascripts/lib/utils/sticky.js new file mode 100644 index 00000000000..f53acaa17b1 --- /dev/null +++ b/app/assets/javascripts/lib/utils/sticky.js @@ -0,0 +1,21 @@ +export const isSticky = (el, stickyTop) => { + const top = el.getBoundingClientRect().top; + + if (top === stickyTop) { + el.classList.add('is-stuck'); + } else { + el.classList.remove('is-stuck'); + } +}; + +export default (el) => { + const computedStyle = window.getComputedStyle(el); + + if (!/sticky/.test(computedStyle.position)) return; + + const stickyTop = parseInt(computedStyle.top, 10); + + document.addEventListener('scroll', () => isSticky(el, stickyTop), { + passive: true, + }); +}; |