Created
December 12, 2019 11:26
-
-
Save AvgustPol/721f23ae13ef3811184513f015bb84d9 to your computer and use it in GitHub Desktop.
Rotation animation using pure JS (javascript) and CSS
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
<!DOCTYPE html> | |
<html> | |
<body> | |
<style> | |
.rotatable { | |
-webkit-transition: all 0.3s ease-in-out; | |
-moz-transition: all 0.3s ease-in-out; | |
-o-transition: all 0.3s ease-in-out; | |
transition: all 0.3s ease-in-out; | |
} | |
.rotated90 { | |
transform:rotate(90deg); | |
-webkit-transform:rotate(90deg); | |
-moz-transform:rotate(90deg); | |
-o-transform:rotate(90deg); | |
} | |
.example { | |
width: 100px; | |
height: 100px; | |
} | |
</style> | |
<button onclick="myFunction()">"Rotate hello world" </button> | |
<br> | |
<br> | |
<br> | |
<div class="rotatable example" id="rotateMePlease"> | |
Hello world! | |
</div> | |
<script> | |
function myFunction() { | |
var elementToRotate = document.getElementById("rotateMePlease"); | |
elementToRotate.classList.toggle("rotated90"); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment