테마의 헤더 탭에 다음과 같은 코드를 추가할 수 있습니다
<div class="header-anchor"></div>
<script type="text/discourse-plugin" version="0.8">
if (!"IntersectionObserver" in window) return;
const { on } = require("discourse-common/utils/decorators");
const stickyClass = "sticky";
api.modifyClass("component:site-header", {
@on("didInsertElement")
stickyHeaderCheck() {
const anchor = document.querySelector(".header-anchor");
const header = this.element;
new IntersectionObserver(entries => {
if (!entries[0].isIntersecting) {
header.classList.add(stickyClass);
} else {
header.classList.remove(stickyClass);
}
}).observe(anchor);
}
});
</script>
이 코드는 헤더 래퍼에 sticky 클래스를 추가하여, 스크롤할 때 헤더가 상단에 고정된 상태일 때 커스텀 CSS를 적용할 수 있게 해줍니다.
.d-header {
box-shadow: none;
transition: box-shadow 0.3s ease-in-out;
will-change: box-shadow;
.sticky & {
box-shadow: 0 3px 5px rgba(57, 63, 72, 0.3);
}
}