.bar {
  position: fixed;
  top: 0;
  left: 0;
  inline-size: 100%;
  block-size: 4px;
  background-color: royalblue;
  transform-origin: left;
  scale: 0 1;
}

@supports (animation-timeline: scroll()) {
  .bar {
    animation: fill linear both;
    animation-timeline: scroll(root);
  }
}

@keyframes fill {
  to {
    scale: 1 1;
  }
}

.long {
  block-size: 200vh;
}
