Skip to content

Instantly share code, notes, and snippets.

@AvgustPol
Created December 12, 2019 11:26
Show Gist options
  • Save AvgustPol/721f23ae13ef3811184513f015bb84d9 to your computer and use it in GitHub Desktop.
Save AvgustPol/721f23ae13ef3811184513f015bb84d9 to your computer and use it in GitHub Desktop.
Rotation animation using pure JS (javascript) and CSS
<!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