Timeline v3

In this example below you will see how to do a Timeline v3 with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by q51, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright q51 ©
  • HTML
  • CSS
  • JavaScript
    <div class="timelineBreak">
  <svg class="timelineBreakSVG" enable-background="new 0 0 391 128" version="1.1" viewBox="0 0 391 128" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
    <polyline class="st1" points="194.5,128 194.5,0" stroke="#eeeeee" fill="none" stroke-width="5" stroke-dasharray="15,12"/>
    <g id="leftPath0" mask="url(#pathMask4)">
      <polyline class="st0" points="194.5,128 194.5,0" stroke="#f47c67" fill="none" stroke-width="5" stroke-dasharray="15,12"/>
    </g>
    <mask id="pathMask4">
      <polyline class="st3-0" points="195.5 0, 195.5 64" stroke="#ffffff" fill="none" stroke-width="8"/>
    </mask>
  </svg>
</div>

<div class="timelineBreak">
  <svg class="timelineBreakSVG" enable-background="new 0 0 391 128" version="1.1" viewBox="0 0 391 128" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
    <polyline class="st1" points="2.5,128 2.5,64 194.5,64 194.5,0 " stroke="#eeeeee" fill="none" stroke-width="5" stroke-dasharray="15,12"/>
    <polyline class="st1" points="386.5,128 386.5,64 194.5,64 " stroke="#eeeeee" fill="none" stroke-width="5" stroke-dasharray="15,12"/>
    <g id="leftPath1" mask="url(#leftPathMask1)">
      <polyline class="st0" points="2.5,128 2.5,64 194.5,64 194.5,0 " stroke="#f47c67" fill="none" stroke-width="5" stroke-dasharray="15,12"/>
    </g>
    <g id="rightPath1" mask="url(#rightPathMask1)">
      <polyline class="st0" points="386.5,128 386.5,64 194.5,64 " stroke="#f47c67" fill="none" stroke-width="5" stroke-dasharray="15,12"/>
    </g>
    <mask id="leftPathMask1">
      <polyline class="st3" points="195.5 0 195.5 64 3.5 64  3.5 128" stroke="#ffffff" fill="none" stroke-width="8"/>
    </mask>
    <mask id="rightPathMask1">
      <polyline class="st3" points="195.5 0 195.5 64 387.5 64 387.5 128" stroke="#ffffff" fill="none" stroke-width="8"/>
    </mask>
  </svg>
</div>

<div class="timelineBreak">
  <svg class="timelineBreakSVG" enable-background="new 0 0 391 128" version="1.1" viewBox="0 0 391 128" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
    <polyline class="st1" points="386.5,0 386.5,64 2.5,64 2.5,128" stroke="#eeeeee" fill="none" stroke-width="5" stroke-dasharray="15,12"/>
    <g id="leftPath2" mask="url(#leftPathMask2)">
      <polyline class="st0" points="386.5,0 386.5,64 2.5,64 2.5,128" stroke="#f47c67" fill="none" stroke-width="5" stroke-dasharray="15,12"/>
    </g>
    <mask id="leftPathMask2">
      <polyline class="st3-2" points="386.5,0 386.5,64 2.5,64 2.5,128" stroke="#ffffff" fill="none" stroke-width="8"/>
    </mask>
  </svg>
</div>

<div class="timelineBreak">
  <svg class="timelineBreakSVG" enable-background="new 0 0 391 128" version="1.1" viewBox="0 0 391 128" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
    <polyline class="st1" points="2.5,128 2.5,64 194.5,64 194.5,0 " stroke="#eeeeee" fill="none" stroke-width="5" stroke-dasharray="15,12"/>
    <polyline class="st1" points="386.5,128 386.5,64 194.5,64 " stroke="#eeeeee" fill="none" stroke-width="5" stroke-dasharray="15,12"/>
    <g id="leftPath3" mask="url(#leftPathMask3)">
      <polyline class="st0" points="2.5,128 2.5,64 194.5,64 194.5,0 " stroke="#f47c67" fill="none" stroke-width="5" stroke-dasharray="15,12"/>
    </g>
    <g id="rightPath3" mask="url(#rightPathMask3)">
      <polyline class="st0" points="386.5,128 386.5,64 194.5,64 " stroke="#f47c67" fill="none" stroke-width="5" stroke-dasharray="15,12"/>
    </g>
    <mask id="leftPathMask3">
      <polyline class="st3" points="195.5 0 195.5 64 3.5 64  3.5 128" stroke="#ffffff" fill="none" stroke-width="8"/>
    </mask>
    <mask id="rightPathMask3">
      <polyline class="st3" points="195.5 0 195.5 64 387.5 64 387.5 128" stroke="#ffffff" fill="none" stroke-width="8"/>
    </mask>
  </svg>
</div>

<div class="timelineBreak">
  <svg class="timelineBreakSVG" enable-background="new 0 0 391 128" version="1.1" viewBox="0 0 391 128" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
    <polyline class="st1" points="2.5,128 2.5,64 194.5,64 194.5,0 " stroke="#eeeeee" fill="none" stroke-width="5" stroke-dasharray="15,12"/>
    <polyline class="st1" points="386.5,128 386.5,64 194.5,64 " stroke="#eeeeee" fill="none" stroke-width="5" stroke-dasharray="15,12"/>
    <g id="leftPath4" mask="url(#leftPathMask4)">
      <polyline class="st0" points="2.5,128 2.5,64 194.5,64 194.5,0 " stroke="#f47c67" fill="none" stroke-width="5" stroke-dasharray="15,12"/>
    </g>
    <g id="rightPath4" mask="url(#rightPathMask4)">
      <polyline class="st0" points="386.5,128 386.5,64 194.5,64 " stroke="#f47c67" fill="none" stroke-width="5" stroke-dasharray="15,12"/>
    </g>
    <mask id="leftPathMask4">
      <polyline class="st3" points="195.5 0 195.5 64 3.5 64  3.5 128" stroke="#ffffff" fill="none" stroke-width="8"/>
    </mask>
    <mask id="rightPathMask4">
      <polyline class="st3" points="195.5 0 195.5 64 387.5 64 387.5 128" stroke="#ffffff" fill="none" stroke-width="8"/>
    </mask>
  </svg>
</div>


/*Downloaded from https://www.codeseek.co/q51/timeline-v3-mLajPw */
    body {
  width: 600px;
  margin: auto;
  padding-top: 600px;
  padding-bottom: 600px;
  font-family: sans-serif;
  font-size: 0.8em;
  line-height: 1.5em;
}


.timelineBreak{
  padding-top: 40px;
  padding-bottom: 40px;
}


.timelineBreak .st3-0{
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  transition: 01s;
}

.timelineBreak.active .st3-0{
  stroke-dashoffset: 0;
}

.timelineBreak.inactive .st3-0{
  stroke-dashoffset: 100!important;
}

/*  */

.timelineBreak .st3{
  stroke-dasharray: 320;
  stroke-dashoffset: 320;
  transition: 01s;
}

.timelineBreak.active .st3{
  stroke-dashoffset: 0;
}

.timelineBreak.inactive .st3{
  stroke-dashoffset: 320!important;
}

/*  */

.timelineBreak .st3-2{
  stroke-dasharray: 500;
  stroke-dashoffset: 500;
  transition: 01s;
}

.timelineBreak.active .st3-2{
  stroke-dashoffset: 0;
}

.timelineBreak.inactive .st3-2{
  stroke-dashoffset: 500!important;
}


/*Downloaded from https://www.codeseek.co/q51/timeline-v3-mLajPw */
    $( document ).ready(function() {
    //first, get and cache the viewport size
    var vw = $( window ).innerWidth();
    var vh = $( window ).innerHeight();
    // refresh these on resize!
    $( window ).resize(function(){
      vw = $( window ).innerWidth();
      vh = $( window ).innerHeight();
    });
    $( window ).scroll(function(){
      //check each entry for its position relative to the viewport
      $('.timelineBreak').each(function(){
        var offsetTop = $(this).offset();
        var windowScrollTop = $(window).scrollTop();
        //Check if it's past 50%
        var ViewCheck = offsetTop.top - (windowScrollTop+(vh/2));
        // console.log(ViewCheck);
        if (ViewCheck < 0){
           //Add/remove classes as needed
          $(this).addClass('active').removeClass('inactive');
        } else {
          $(this).removeClass('active').addClass('inactive'); 
        }
      })
    })
});

Comments