I am trying to do text reveal animation on a dynamically injected h1 element which has text wrapped inside span element, but trying to animate with translate property doesn't seem to work. I've added window.getComputedStyle()
to recalculate the styles before adding the transform: translate property to get the transform property working but still no luck. Am I doing something wrong? Thanks!!
Here's the code!
var textDiv = document.querySelector('.text');
textDiv.innerHTML = '<h1><span>Reveal</span></h1>';
var spanText = document.querySelector('span');
spanText.classList.add('show');
window.getComputedStyle(spanText).getPropertyValue('transform');
spanText.style.transform = 'translateY(100%)';
body {
background-color: #bedcff;
font-family: Helvetica;
font-weight: bold;
}
.container {
padding: 100px 20px 0;
max-width: 960px;
margin: 0 auto;
}
h1 {
margin: 0;
text-align: center;
font-size: 200px;
overflow: hidden;
line-height: 1;
}
h1 span {
-webkit-transform: translateY(0%);
transform: translateY(0%);
-webkit-transition: -webkit-transform 1s ease;
transition: -webkit-transform 1s ease;
transition: transform 1s ease;
transition: transform 1s ease, -webkit-transform 1s ease;
}
<body>
<div class="container">
<div class="text">
</div>
</div>
</body>