The CSS transitions are not recognizing the inline variables, or if they are, they are not receiving the correct information.
Below is an illustration of how the inline variables are defined in the HTML:
<p class="hidden" style="--order: 1;" >ABC</p>
This is how the variable is being referenced within the CSS:
section p {
transition-delay: calc(200ms * var(--order));
}
Here is a complete example of HTML code with JavaScript. The objective is to scroll down and have the sections transition in, followed by each paragraph transitioning in after 200ms from one another.
<html>
<head>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;400;700&display=swap');
body {
background-color: #131316;
color: #ffffff;
padding: 0;
margin: 0;
font-family: 'Poppins', sans-serif;
}
section {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 0px 20%;
}
.hidden {
opacity: 0;
filter: blur(5px);
transform: translateX(-100%);
transition: all 1s;
}
.show {
opacity: 1;
filter: blur(0);
transform: translateX(0);
}
section p {
transition-delay: calc(200ms * var(--order));
}
</style>
</head>
<body>
<section class="hidden">
<p class="hidden" style="--order: 1;" >Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts.</p>
<p class="hidden" style="--order: 2;" >Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia.</p>
<p class="hidden" style="--order: 3;" >It is a paradisematic country, in which roasted parts of sentences fly into your mouth.</p>
<p class="hidden" style="--order: 4;" >Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar.</p>
<p class="hidden" style="--order: 5;" >The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way.</p>
</section>
<section class="hidden">
<p class="hidden" style="--order: 1;" >Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts.</p>
<p class="hidden" style="--order: 2;" >The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way.</p>
</section>
<script>
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
entry.target.classList.toggle('show', entry.isIntersecting);
});
});
const hiddenElements = document.querySelectorAll('.hidden');
hiddenElements.forEach((el) => observer.observe(el));
</script>
</body>
</html>