Fill a circle on scroll in CSS

I’m trying to make a stem filling with a color and with circles for steps along the stem.

This is an example of what I’m currently aiming for: https://codepen.io/nicklassandell/pen/ztGac

This is currently what I have: https://codepen.io/TheOshika/full/xxRRVNb (the design is similar to the above code but I wrote the code from scratch)
I’m using a scrollspy script in order to trigger a filling animation in the circles. However I’m not satisfied with it because the offset for the trigger is too difficult to set for a responsive design. I’m now thinking about removing the javascript part and instead having a stem filling the circles with the scrolling, but no animation.

This is what I’m looking for, except I don’t know how to make the background color in the stem fill the circles:

.header {
  position: relative;
  height: 800px;
  background: blueviolet;
  z-index: 3;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: #4c63b6;
}

.container {
  margin: 0px auto;
  position: relative;
}

/* stem */
.filling-stem {
  position: sticky;
  z-index: 1;
  float: left;
  top: 0;
  left: 50%;
  transform: translate(-50%, 0);
  height: 50vh;
  width: 5px;
  background-color: #bed0f7;
}

.stem-background {
  position: absolute;
  z-index: 0;
  left: 50%;
  transform: translate(-50%, 0);
  height: 100%;
  width: 5px;
  background-color: #1f2933;
}

.stem-nav {
  position: absolute;
  z-index: 2;
  left: 50%;
  transform: translate(-50%, 0);
  height: 100%;
}

#my-awesome-nav {
  display: flex;
  height: 100%;
  justify-content: space-around;
  flex-direction: column;
  list-style: none;
  margin-left: 0;
  padding-left: 0;
}

#my-awesome-nav li a {
  border: solid 3px black;
  border-radius: 50%;
  display: inline-block;
  background-color: #1f2933;
}

#my-awesome-nav li a .color-change {
  height: 40px;
  width: 40px;
  background-color: #1f2933;
  border-radius: 50%;
}

/* timeline */
.timeline-container {
  position: relative;
}

.step-container {
  margin: 0 25% 0 25%;
  display: flex;
  align-items: center;
  height: 1500px;
}

/* footer */
footer {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 1000px;
  width: 100%;
  background-color: black;
  color: white;
}
<div class="container">
  <div class="container-inner">

    <div class="filling-stem"></div>
    <div class="header"></div>

    <div class="timeline-container">
      <div class="timeline-container-inner">
        <div class="stem-background"></div>
        <div class="stem-nav">
          <ul id="my-awesome-nav">
            <li data-index="0"><a href="#step-one">
                <div class="color-change one"></div>
              </a></li>
            <li data-index="1"><a href="#step-two">
                <div class="color-change two"></div>
              </a></li>
            <li data-index="2"><a href="#step-three">
                <div class="color-change three"></div>
              </a></li>
            <li data-index="3"><a href="#step-four">
                <div class="color-change four"></div>
              </a></li>
            <li data-index="4"><a href="#step-five">
                <div class="color-change five"></div>
              </a></li>
          </ul>
        </div>
        <div class="step-container">
          <div class="step-container-inner">
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<footer>
  <p>End of the page</p>
</footer>

19 thoughts on “Fill a circle on scroll in CSS”

Leave a Comment