We all are quite familiar with vertical timelines: all instant messaging applications use them. A current trend in web design is to use a similar structure, but to show a process rather than a sequence of events. That is why timeline-like structures are often used for the “How it works” page.
The inspiration for this nugget came from the Zurb University page. The result is very clean yet dynamic, with room for big illustrations in the center.
Icons: Nucleo Library
We wrapped the entire timeline into a <section> element. The .cd-timeline-block div represents a “block” of content. We finally split the image/icon and the text content into 2 separates divs.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<section id="cd-timeline"> <div class="cd-timeline-block"> <div class="cd-timeline-img"> <img src="img/cd-icon-picture.svg" alt="Picture"> </div> <!-- cd-timeline-img --> <div class="cd-timeline-content"> <h2>Title of section 1</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iusto, optio, dolorum provident rerum aut hic quasi placeat iure tempora laudantium ipsa ad debitis unde? Iste voluptatibus minus veritatis qui ut.</p> <a href="#0" class="cd-read-more">Read more</a> <span class="cd-date">Jan 14</span> </div> <!-- cd-timeline-content --> </div> <!-- cd-timeline-block --> <div class="cd-timeline-block"> <!-- ... --> </div> </section> |
We used a ::before selector in absolute position to create the vertical line. Images/icons are in absolute position too, this way it was super easy to create the responsive structure simply by adding a margin-left to the text content.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#cd-timeline { position: relative; padding: 2em 0; margin-top: 2em; margin-bottom: 2em; } #cd-timeline::before { /* this is the vertical line */ content: ''; position: absolute; top: 0; left: 18px; height: 100%; width: 4px; background: #d7e4ed; } |
2 bounce-in animations, both for the image/icon and the text content, have been created and are visible only for desktop users. For the animation to work we had to create 2 classes: .is-hidden, which is used to hide by default all the content blocks that are off the viewport; when the user scrolls down, we add a .bounce-in class to both the .cd-timeline-img and .cd-timeline-content to make the elements visible and trigger the animation.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
.cssanimations .cd-timeline-img.is-hidden { visibility: hidden; } .cssanimations .cd-timeline-img.bounce-in { visibility: visible; animation: cd-bounce-1 0.6s; } @keyframes cd-bounce-1 { 0% { opacity: 0; transform: scale(0.5); } 60% { opacity: 1; transform: scale(1.2); } 100% { transform: scale(1); } } |
As explained in the “Adding style” section, we used jQuery to hide content blocks which are off the viewport, using the class .is-hidden. When user scrolls and a new block enters the viewport, we add the class .bounce-in to both .cd-timeline-img and .cd-timeline-content (and remove the .is-hidden class) to trigger the animation.
|
1 2 3 4 5 6 7 |
$(window).on('scroll', function(){ $timeline_block.each(function(){ if( $(this).offset().top <= $(window).scrollTop()+$(window).height()*0.75 && $(this).find('.cd-timeline-img').hasClass('is-hidden') ) { $(this).find('.cd-timeline-img, .cd-timeline-content').removeClass('is-hidden').addClass('bounce-in'); } }); }); |