Skip to content
Snippets Groups Projects
Verified Commit 7ce70dd5 authored by Phil Hughes's avatar Phil Hughes
Browse files

Dynamically create offset for sticky bar

parent 41068df7
No related branches found
No related tags found
No related merge requests found
export const isSticky = (el, scrollY, stickyTop) => {
export const createPlaceholder = () => {
const placeholder = document.createElement('div');
placeholder.classList.add('sticky-placeholder');
return placeholder;
};
export const isSticky = (el, scrollY, stickyTop, insertPlaceholder) => {
const top = Math.floor(el.offsetTop - scrollY);
 
if (top <= stickyTop) {
if (top <= stickyTop && !el.classList.contains('is-stuck')) {
const placeholder = insertPlaceholder ? createPlaceholder(el) : null;
const heightBefore = el.offsetHeight;
el.classList.add('is-stuck');
} else {
if (insertPlaceholder) {
el.parentNode.insertBefore(placeholder, el.nextElementSibling);
placeholder.style.height = `${heightBefore - el.offsetHeight}px`;
}
} else if (top > stickyTop && el.classList.contains('is-stuck')) {
el.classList.remove('is-stuck');
if (insertPlaceholder && el.nextElementSibling.classList.contains('sticky-placeholder')) {
el.nextElementSibling.remove();
}
}
};
 
export default (el) => {
export default (el, insertPlaceholder = true) => {
if (!el) return;
 
const computedStyle = window.getComputedStyle(el);
Loading
Loading
@@ -17,7 +37,7 @@ export default (el) => {
 
const stickyTop = parseInt(computedStyle.top, 10);
 
document.addEventListener('scroll', () => isSticky(el, window.scrollY, stickyTop), {
document.addEventListener('scroll', () => isSticky(el, window.scrollY, stickyTop, insertPlaceholder), {
passive: true,
});
};
Loading
Loading
@@ -451,7 +451,7 @@
}
 
.files {
margin-top: -1px;
margin-top: 1px;
 
.diff-file:last-child {
margin-bottom: 0;
Loading
Loading
@@ -586,11 +586,6 @@
top: 76px;
}
 
+ .files,
+ .alert {
margin-top: 1px;
}
&:not(.is-stuck) .diff-stats-additions-deletions-collapsed {
display: none;
}
Loading
Loading
@@ -608,7 +603,7 @@
 
+ .files,
+ .alert {
margin-top: 32px;
// margin-top: 32px;
}
}
}
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment