Skip to content

Instantly share code, notes, and snippets.

@shshaw
Created January 24, 2018 23:08
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 shshaw/37a31152da24defaf0ecf067f65fa1a6 to your computer and use it in GitHub Desktop.
Save shshaw/37a31152da24defaf0ecf067f65fa1a6 to your computer and use it in GitHub Desktop.
Apply a hidden style with WAAPI.
<div style="opacity: 0; visibility: hidden;">
How is this box visible?
</div>
var el = document.querySelector('div');
var newStyle = {
//transform: 'translate(150px,150px)',
opacity: '1',
visibility: 'visible'
}
el.animate(
// Must be duplicated for WAAPI compatibility
[ newStyle, newStyle ],
{
// Duration cannot be 0 so we set it to 1ms
duration: 1,
// Have to fill it for the style to stick
fill: 'both'
}
);
setTimeout(function(){
console.log(window.getComputedStyle(el).transform);
},60) // Have to wait for a full frame to pass to see the style
html { height: 100%; display: flex; }
body { margin: auto; }
div {
display: block;
background: #000;
color: #FFF;
box-sizing: border-box;
padding: 15px;
text-align: center;
opacity: 0;
visibility: hidden;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment