Skip to content

Commit

Permalink
Details에 ID 지정 및 로딩 시 오픈 + 스크롤 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
XiNiHa committed Mar 15, 2024
1 parent f3b42d1 commit 4236649
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/components/gitbook/Details.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<details class="group/details my-4 border rounded hover:border-orange">
---
interface Props {
id?: string;
}
const { id } = Astro.props;
---

<details id={id} class="group/details my-4 border rounded hover:border-orange">
<style>
summary > .chevron {
width: 1.25em;
Expand Down Expand Up @@ -29,3 +37,13 @@
</div>
</div>
</details>
<script>
const hash = window.location.hash;
if (hash) {
const el = document.querySelector(hash);
if (el && el.tagName === "DETAILS") {
el.setAttribute("open", "");
el.scrollIntoView({ block: "start" });
}
}
</script>

0 comments on commit 4236649

Please sign in to comment.