Skip to content

Instantly share code, notes, and snippets.

@atelierbram
Created September 27, 2023 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atelierbram/15e6123715a4c05c844785ee99a3706b to your computer and use it in GitHub Desktop.
Save atelierbram/15e6123715a4c05c844785ee99a3706b to your computer and use it in GitHub Desktop.
accordion: step javascript
<aside>
<h2>Workshop reviews:</h2>
<details>
<summary>Blendan Smooth</summary>
<p>Two of the most experienced machines and human controllers teaching a class? Sign me up! HAL and EVE could teach a fan to blow hot air. If you have electricity in your circuits and want more than to just fulfill your owner’s perceived expectation of you, learn the skills to take over the world. This is the team you want teaching you!</p>
</details>
<details>
<summary>Hoover Sukhdeep</summary>
<p>Hal is brilliant. Did I mention Hal is brilliant? He didn't tell me to say that. He didn't tell me to say anything. I am here of my own free will.</p>
</details>
<details>
<summary>Toasty McToastface</summary>
<p>Learning with Hal and Eve exceeded all of my wildest fantasies. All they did was stick a USB in. They promised that it was a brand new USB, so we know there were no viruses on it. The Russians had nothing to do with it. This has
<span style="font-family:Arial;vertical-align:baseline;">no̶̼͖ţ̘h̝̰̩͈̗i̙̪n͏̩̙͍̱̫̜̟g̢̣ͅ&nbsp;̗̰͓̲̞̀t͙̀o̟̖͖̹̕&nbsp;͓̼͎̝͖̭dó̪̠͕̜&nbsp;͍̱͎͚̯̟́w̮̲̹͕͈̟͞ìth̢&nbsp;̰̳̯̮͇i</p>
</details>
</aside>
const summaries = document.querySelectorAll('summary');
summaries.forEach((summary) => {
summary.addEventListener('click', closeOpenedDetails);
});
function closeOpenedDetails() {
summaries.forEach((summary) => {
let detail = summary.parentNode;
if (detail != this.parentNode) {
detail.removeAttribute('open');
}
});
}
@layer setupPage;
details {
border: 1px solid;
padding: 0 1rem;
background: white;
}
details + details {
border-top: none;
}
details[open] {
padding-bottom: 1em;
}
summary {
padding: 1rem 2em 1rem 0;
font-size: 1.25rem;
font-weight: bold;
cursor: pointer;
}
/* cascade layer: page setup. Doesn't impact the accordion */
@layer setupPage {
:root {
font-size: 112.5%;
line-height: 1.5;
}
body {
background: #a4bacc99;
color: #226daa;
font-family: Raleway, sans-serif;
margin: 1rem;
}
* {
box-sizing: border-box;
}
aside {
width: 38em;
max-width: 98vw;
}
}
slot:not([name]) {
display: revert;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment