<div class="question-1">
<h1>How fast did the DeLorean need to go to time travel in Back to the Future?</h1>
<div class="scroller">
<div>Scroll to answer</div>
<span></span>
</div>
<div class="number">
<span></span>
</div>
</div>
</div>
@property --num {
syntax: "<integer>";
inherits: true;
initial-value: 0;
}
.question-1 {
timeline-scope: --question-1;
}
.scroller {
padding: 2rem;
height: 100px;
border: 10px solid black;
overflow: auto;
scroll-timeline: --question-1 block;
margin-block-end: 1rem;
> span {
display: block;
height: 2000px;
}
> div {
position: sticky;
top: 40px;
text-align: center;
}
}
.number {
position: sticky;
top: 0;
font-size: 72px;
text-align: center;
animation: counter linear both;
animation-timeline: --question-1;
span {
display: grid;
}
@container style(--num: 88) {
span::before {
content: "Correct!";
display: block;
color: green;
font-size: 36px;
}
}
span::after {
counter-set: num var(--num);
content: counter(num);
}
}
@supports not (scroll-timeline: --x) {
.number::after {
font-size: 20px;
color: red;
content: "No support.";
}
}
@keyframes counter {
from {
--num: 0;
}
to {
--num: 100;
}
}
html {
font-family: system-ui;
font-variation-settings: "wght" 900, "wdth" 700;
}
body {
margin: 0;
padding: 2rem;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.