Created
August 10, 2019 08:45
-
-
Save antony/7f55dbe72868e5bf2920a0611e4e47ae to your computer and use it in GitHub Desktop.
An example of a div which can flip its content
This file contains hidden or 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
<div class="card-container"> | |
<div class="card"> | |
{#if flipped} | |
<div class="side" transition:turn> | |
<slot name="front"></slot> | |
</div> | |
{:else} | |
<div class="side back" transition:turn> | |
<slot name="back"></slot> | |
</div> | |
{/if} | |
</div> | |
</div> | |
<script> | |
let flipped = false | |
function turn(node, { | |
delay = 0, | |
duration = 500 | |
}) { | |
return { | |
delay, | |
duration, | |
css: (t, u) => ` | |
transform: rotateY(${1 - (u * 180)}deg); | |
opacity: ${1 - u}; | |
` | |
}; | |
} | |
export function flip () { | |
flipped = !flipped | |
} | |
</script> | |
<style> | |
.card-container { | |
position: relative; | |
height: 100%; | |
width: 100%; | |
} | |
.card { | |
width: 100%; | |
height: 100%; | |
position: absolute; | |
perspective: 600; | |
} | |
.side { | |
position: absolute; | |
height: 100%; | |
width: 100%; | |
overflow: hidden; | |
color: #fff; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment