Skip to content

Commit

Permalink
Update banner to animate on scroll (istio#9784)
Browse files Browse the repository at this point in the history
* Update banner to animate on scroll

* Correct indentation

* Fix linting issue
  • Loading branch information
rytswd authored May 18, 2021
1 parent 053e7b9 commit a7141a0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/sass/misc/_banners.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
.banner-container {
display: none;
top: $headerHeight;
transition: top .2s;

&.active {
top: $activeHeaderHeight;
}

@media screen AND (min-width: $bp-md) {
display: block;
position: fixed;
Expand Down
23 changes: 23 additions & 0 deletions src/ts/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,33 @@ function handleEvents(): void {
}
}

const banner = getByClass("banner-container");
function toggleActiveHeader(): void {
const top = window.scrollY;

if (!banner) {
return;
}

if (top >= 10) {
banner[0].classList.add("active");
} else {
banner[0].classList.remove("active");
}
}

loadRemainingEventImpressions();
displayEvents("banner");
displayEvents("sticker");
saveRemainingEventImpressions();

if (document.readyState !== "loading") {
toggleActiveHeader();
}

listen(window, "scroll", () => {
toggleActiveHeader();
});
}

handleEvents();

0 comments on commit a7141a0

Please sign in to comment.