Skip to content

Instantly share code, notes, and snippets.

@silverwind
Created May 26, 2013 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silverwind/5652844 to your computer and use it in GitHub Desktop.
Save silverwind/5652844 to your computer and use it in GitHub Desktop.
Untitled
body {
background: #222
}
div {
height: 200px;
width: 200px;
position:absolute;
background: #f51;
transition: left .5s ease;
}
.left { left: 50px }
.right { left: 500px }
// Remove leftover divs from previous run
var element = document.getElementsByTagName("div");
for (index = element.length - 1; index >= 0; index--) {
element[index].parentNode.removeChild(element[index]);
}
// Create a new div dynamically
var div = document.createElement("div");
// Initialize class to "left"
div.setAttribute("class", "left");
// Add it
document.body.appendChild(div);
// Switch the class so the transition triggers.
window.setTimeout(function(){
div.setAttribute("class", "right");
},50); // Why won't the transition trigger with short or no delay?
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"javascript"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment