Update banner to animate on scroll (#9784)

* Update banner to animate on scroll

* Correct indentation

* Fix linting issue
This commit is contained in:
Ryota 2021-05-18 21:57:37 +01:00 committed by GitHub
parent 053e7b9b4e
commit a7141a0c47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -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;

View File

@ -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();