diff options
author | Phil Hughes <me@iamphill.com> | 2017-07-27 17:53:04 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-08-03 19:03:49 +0300 |
commit | b507682d6e799f737c05f27201dc4a0dbe3aba1d (patch) | |
tree | b8a597d6bd605a4a858952e913627dd9c86eb338 /app/assets/javascripts/lib/utils | |
parent | 655510ec9a658c28f50ccb0caea394f5db7cae59 (diff) |
made the changed files holder sticky
Diffstat (limited to 'app/assets/javascripts/lib/utils')
-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, + }); +}; |