Timeline Component

A scrollable component useful for creating visually interesting and interactive timelines.

This component requires some knowledge of HTML. The code is annotated, but proceeding without experience may result in errors. To learn more about HTML, CSS and Javascript, visit W3Schools.

On this Page

Last Updated: 12/18/2024

Component Elements

HTML Snippet

The HTML Snippet is where the majority of the component resides. It contains the HTML code which, in turn, contains the CSS styles, HTML elements and scripts.

HTML Tab
Property Value
Open the default code in Box.
Options Tab
Property Value
Description unchanged
HTML Filter Off
Component Handle Show (default)

Editing the Component

In this Section

To make basic edits to this component, only knowledge of HTML is needed. More advanced edits can be made by changing the stylesheet which requires knowledge of CSS.

Initially, the default component provides four phases with generic names and placeholder text. The component should have at least two phases and has no maximum. 

Changing the Existing Phases

Each phase contains one block of HTML which contains four total elements:

    
<a href="#" alt=""> 
  <div class="Pending">
    <h2>Phase One</h2>
    <p>Completed</p>
  </div>
</a>
    
    
Phase HTML Elements Breakdown
Element Tag Additional Properties Description
<div id="timeline-component"> none Acts as a wrapper for the component so the HTML Snippet only changes itself.
<a href="#" alt=""> href Where clicking on the phase should link to. See Writing and Adding Links for best practices.
alt Provide a short, detailed description of where the link goes.
<div class="completed"> class The class determines the appearance of the phase. There are three appearances available: pending, in-progress and completed. 
<h2>Phase One</h2> none Should contain the phase name.
<p>Completed</p> none Should contain either the phase status, phase description or the time frame of the phase (i.e. December 2024 to April 2025).

Adding More Phases

To add more phases, copy-paste and edit the phase HTML elements. Each phase begins with <a> and ends with <a>. There is no maximum number of phases, though it's recommended not to exceed 10.

Removing Phases

To remove a phase, delete that phase's HTML elements. Each phase begins with <a> and ends with <a>. The other phases should automatically collapse to avoid leaving a white space.

Advanced Editing

In this Section

Making advanced edits may cause the component to break. Use caution and only edit these sections if experienced with CSS and Javascript.

Adjusting the Minimum Width of Phases

The width of the phase component is dynamic but has a default minimum width of 200px. To change the minimum width, change the min-width property of the #timeline-component a div on line 72 to the desired width. If the change is not visible, the text within the elements is too long since the element resizes to fit the text.

Adding Statuses or Colors

The default statuses and colors for the timeline component are after line 88. To add a status, add a new class like #timeline-component status-name, add properties for background-color and color, and change their values as desired. Note: background-color defines the color of the element's background and color defines the color of the text.


These classes can then be referenced in lieu of the existing ones in the HTML element of the phases.

Changing Colors

To change the color of the existing statuses, navigate to line 88 in the HTML Snippet. The background-color and color of #timeline-component .completed, #timeline-component .in-progress and #timeline-component .pending can be changed to new colors as desired.


Colors must follow UB brand guidelines and be accessible.

To remove the linking capability of the phases, remove the href and alt attributes from the opening <a> and change the <a></a> to <div></div>


For example:

    
<a href="#" alt="">     <!-- Change <a> to <div> and remove the attributes. -->
  <div class="completed">
    <h2>Phase One</h2>
    <p>Completed</p>
  </div>
</a>                    <!-- Change </a> to </div>. -->
    
    

Becomes:

	
<div>
  <div class="completed">
    <h2>Phase One</h2>
    <p>Completed</p>
  </div>
</div>
    
    

Changing the Scrolling Behavior

The amount the timeline is scrolled can be forced to make sure the correct phase is in view. By default, the component is set to scroll until the first pending phase is in view.

To change the scrolling behavior of the component, scroll to line 167:

    
const scrollToElement = timelineComponent.getElementsByClassName("pending")[0];
    
    

Changing .getElementsByClassName("pending") will change the class the script looks for and changing [0] will change which instance of that class will be scrolled to. For example:

    
const scrollToElement = timelineComponent.getElementsByClassName("in-progress")[0];
    
    

This scrolls the component to the first element with the in-progress class.

    
const scrollToElement = timelineComponent.getElementsByClassName("completed")[2];
    
    

This scrolls the component to the third element with the completed class.


Remember!

Javascript arrays are zero-indexed. The first item is [0], the second [1] and so on.

  • 12/19/2024
    • Guidance information updated.
  • 12/17/2024
    • Removed the Content Optimization Container in favor of a div element with the ID timeline-component within the HMTL Snippet.
      • Fixes an issue with our CSS and scripts trying to reference backend UBCMS content when Content Optimization Containers are used.
    • Added style for div elements that are children to the #timeline-component div element.
    • Reorganized script so z indexes now reference all children of the #timeline-component div element.
    • Changed some class declarations for more flexibility.
  • 12/16/2024
    • Component initially created.