Skip to content

Instantly share code, notes, and snippets.

@anonymoussc
Last active August 29, 2015 14:25
CSS Transition animation

##CSS Transition animation

<!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>
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";
});
.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