##CSS Transition animation
Last active
August 29, 2015 14:25
CSS Transition animation
This file contains 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> | |
<head> | |
<title>CSS Transition animation</title> | |
<link href="style.css" rel="stylesheet"/> | |
</head> | |
<body> | |
<div class="cssanimationTimes"> | |
Element with cssanimationTimes class | |
</div> | |
<button id="trigger">Trigger animation</button> | |
<button id="triggerReset">Reset animation</button> | |
<script src="script.js"></script> | |
</body> | |
</html> |
This file contains 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
document.getElementById('trigger').addEventListener('click', function () { | |
var element = document.getElementsByClassName('cssanimationTimes')[0]; | |
// Append classes red and large, to change the background color to red and the width to 300px | |
element.className = element.className + " red large"; | |
}); | |
document.getElementById('triggerReset').addEventListener('click', function () { | |
var element = document.getElementsByClassName('cssanimationTimes')[0]; | |
// Reset | |
element.className = "cssanimationTimes"; | |
}); |
This file contains 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
.cssanimationTimes { | |
transition-property : width, background-color; | |
transition-duration : 2s, 10s; | |
width : 100px; | |
} | |
.large { | |
width : 300px; | |
} | |
.red { | |
background-color : #FF0099; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment