Skip to content

Instantly share code, notes, and snippets.

@sorvell
Created June 17, 2013 20:02
Show Gist options
  • Save sorvell/5799839 to your computer and use it in GitHub Desktop.
Save sorvell/5799839 to your computer and use it in GitHub Desktop.
ShadowDOM polyfill and css transition
<html>
<head>
<script src="../../../ShadowDOM/shadowdom.js"></script>
<style>
.transformy {
-webkit-transition: -webkit-transform 1s;
background: beige;
}
.flipped {
-webkit-transform: rotateY( 180deg );
}
</style>
</head>
<body>
<div id="host">
<div id="target" class="transformy">Hello World</div>
</div>
<button onclick="flip()">Flip</button>
<script>
// make a shadowRoot that distributes
var host = document.querySelector('#host');
var root = host.createShadowRoot();
root.innerHTML = '<content></content>';
//
// toggle flipped class
var target = document.querySelector('#target');
function flip() {
target.setAttribute('class', 'transformy' +
(target.classList.contains('flipped') ? '' : ' flipped'));
//
// works, but does not trigger ShadowDOM distribution
//target.classList.toggle('flipped');
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment