Advent calendar door with CSS star behind - opens on click with transform transition
More info at http://www.red-route.org/articles/opening-doors-advent
Credit due to Ana Tudor and David DeSandro for some tutorials.
<h2>Click on the red door to open it</h2> | |
<div class="door-frame"> | |
<div class="door"></div> | |
<div class="star"></div> | |
</div> |
Advent calendar door with CSS star behind - opens on click with transform transition
More info at http://www.red-route.org/articles/opening-doors-advent
Credit due to Ana Tudor and David DeSandro for some tutorials.
$('.door-frame').click(function () { | |
$(this).find('.door').toggleClass('open'); | |
}); |
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
body { | |
text-align: center; | |
} | |
.door-frame { | |
position: relative; | |
perspective: 150px; | |
border: 1px solid red; | |
width: 100px; | |
height: 75px; | |
margin: 2em auto; | |
cursor: pointer; | |
} | |
.door { | |
border: 1px solid red; | |
display: block; | |
position: absolute; | |
background: red; | |
left: 0; | |
top: 0; | |
width: 100%; | |
height: 100%; | |
z-index: 1; | |
transform: rotateY(0deg); | |
transform-origin: 0; | |
transition-property: all; | |
transition-duration: 0.5s; | |
&.open { | |
transform: rotateY(-120deg); | |
transform-origin: 0 50% 0; | |
width: 15%; | |
} | |
} | |
$star_size: 25px; | |
$star_offset: 15px; | |
.star { | |
position: absolute; | |
width: 0; | |
height: 0; | |
border-left: $star_size solid transparent; | |
border-right: $star_size solid transparent; | |
border-bottom: ($star_size + $star_offset) solid red; | |
top: $star_size - $star_offset; | |
left: $star_size; | |
line-height: 0; | |
font-size: 0; | |
&:after { | |
content:""; | |
position: absolute; | |
width: 0; | |
height: 0; | |
border-left: $star_size solid transparent; | |
border-right: $star_size solid transparent; | |
border-top: ($star_size + $star_offset) solid red; | |
margin: $star_offset 0 0 -$star_size; | |
top: 0; | |
left: -$star_size; | |
line-height: 0; | |
} | |
} |