Created
May 26, 2013 13:46
-
-
Save silverwind/5652844 to your computer and use it in GitHub Desktop.
Untitled
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
body { | |
background: #222 | |
} | |
div { | |
height: 200px; | |
width: 200px; | |
position:absolute; | |
background: #f51; | |
transition: left .5s ease; | |
} | |
.left { left: 50px } | |
.right { left: 500px } |
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
// 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? |
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
{"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