Skip to content

Instantly share code, notes, and snippets.

@ooloth
Last active April 25, 2019 21:30
Show Gist options
  • Save ooloth/116338cd38ee0d92eb15905b34bd14ed to your computer and use it in GitHub Desktop.
Save ooloth/116338cd38ee0d92eb15905b34bd14ed to your computer and use it in GitHub Desktop.
Accordion Example
<script>
import { spring } from 'svelte/motion';
let open = false;
let wrapperHeight = spring(0);
let contentHeight
$: {
if (open) wrapperHeight.set(contentHeight)
else wrapperHeight.set(0)
}
</script>
<style>
div {
overflow: hidden;
background-color: #ff3e00;
}
p {
margin: 0;
padding: 1rem;
color: white;
}
</style>
<button on:click="{() => open = !open}">Toggle</button>
<div style="height: {$wrapperHeight}px" >
<p bind:offsetHeight={contentHeight}>Accordion content...</p>
</div>
<pre>
Wrapper height: {$wrapperHeight}
Content height: {contentHeight}
</pre>
{
"svelte": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment