Skip to content

Commit

Permalink
feat: Overflow shadows
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Holloway authored and Matthew Holloway committed Jul 17, 2024
1 parent 3a839ec commit b00dfd3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
17 changes: 17 additions & 0 deletions ietf/static/css/ietf.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1188,3 +1188,20 @@ blockquote {
padding-left: 1rem;
border-left: solid 1px var(--bs-body-color);
}

.overflow-shadows {
transition: box-shadow 0.5s;
}

.overflow-shadows--both {
box-shadow: inset 0px 21px 18px -20px var(--bs-body-color),
inset 0px -21px 18px -20px var(--bs-body-color);
}

.overflow-shadows--top-only {
box-shadow: inset 0px 21px 18px -20px var(--bs-body-color);
}

.overflow-shadows--bottom-only {
box-shadow: inset 0px -21px 18px -20px var(--bs-body-color);
}
25 changes: 24 additions & 1 deletion ietf/static/js/ietf.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,27 @@ $(document)
// });
});

function overflowShadows(el) {
function handleScroll(){
const canScrollUp = el.scrollTop > 0
const canScrollDown = el.offsetHeight + el.scrollTop < el.scrollHeight
el.classList.toggle("overflow-shadows--both", canScrollUp && canScrollDown)
el.classList.toggle("overflow-shadows--top-only", canScrollUp && !canScrollDown)
el.classList.toggle("overflow-shadows--bottom-only", !canScrollUp && canScrollDown)
}

el.addEventListener("scroll", handleScroll, {passive: true})
handleScroll()

const observer = new IntersectionObserver(handleScroll)
observer.observe(el) // el won't have scrollTop etc when hidden, so we need to recalculate when it's revealed

return () => {
el.removeEventListener("scroll", handleScroll)
observer.unobserve(el)
}
}

$(document)
.ready(function () {
// load data for the menu
Expand All @@ -108,7 +129,7 @@ $(document)
}
attachTo.find(".dropdown-menu")
.remove();
var menu = ['<ul class="dropdown-menu ms-n1 mt-n1">'];
var menu = ['<ul class="dropdown-menu ms-n1 mt-n1 overflow-shadows">'];
var groups = data[parentId];
var gtype = "";
for (var i = 0; i < groups.length; ++i) {
Expand All @@ -127,6 +148,8 @@ $(document)
attachTo.closest(".dropdown-menu");
}
attachTo.append(menu.join(""));

attachTo.find(".overflow-shadows").each(function(){ overflowShadows(this)})
}
}
});
Expand Down

0 comments on commit b00dfd3

Please sign in to comment.