Created with svelte.dev/repl
Last active
April 25, 2019 21:30
-
-
Save ooloth/116338cd38ee0d92eb15905b34bd14ed to your computer and use it in GitHub Desktop.
Accordion Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"svelte": true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment