Created
October 22, 2019 18:52
-
-
Save EduVencovsky/dc907abbefb01077e93be34849c5d7f8 to your computer and use it in GitHub Desktop.
CSS Scale Transition
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
<button id="open">open</button> | |
<div class="box scale"> | |
<h1> | |
hey | |
</h1> | |
</div> |
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
// http://jsfiddle.net/decru76v/4/ | |
var isOpen = false | |
$("#open").click(function(e){ | |
var scale = isOpen ? 0 : 1 | |
$(".scale") | |
.css('transform', `scale(${scale})`) | |
.css('top', this.offsetBottom) | |
.css('left', this.getBoundingClientRect().right) | |
isOpen = !isOpen | |
}) |
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
body{ | |
margin-top:25px; | |
margin-left:25px; | |
} | |
.box{ | |
width:100px; | |
height:100px; | |
background:red; | |
} | |
.scale{ | |
-webkit-transition: all .2s ease-in-out; | |
-moz-transition: all .2s ease-in-out; | |
-o-transition: all .2s ease-in-out; | |
transition: all .2s ease-in-out; | |
transform-origin: left top; | |
transform: scale(0.0); | |
position: absolute; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment