Created
January 24, 2018 23:08
-
-
Save shshaw/37a31152da24defaf0ecf067f65fa1a6 to your computer and use it in GitHub Desktop.
Apply a hidden style with WAAPI.
This file contains 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
<div style="opacity: 0; visibility: hidden;"> | |
How is this box visible? | |
</div> |
This file contains 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
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 |
This file contains 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
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