Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>GreenSock Starter Template</h1>
<p>This loads <strong>ALL</strong> <a href="https://greensock.com">GSAP</a> files including a trial version of every <a href="https://codepen.io/GreenSock/full/OPqpRJ/">bonus plugin</a> (usable on codepen.io only). Hit the "fork" button in the bottom right and experiment to your heart's content. Enjoy!</p>

<div class="content-wrapper">
  <div class="timeline">
    <div class="tl-line-container">
      <div class="tl-line tl-line--desktop"></div>
      <div class="tl-line__marker tl-line__marker--desktop">
        <svg width="48" height="62" viewBox="0 0 48 62" fill="none" xmlns="http://www.w3.org/2000/svg">
          <circle cx="24" cy="24" r="10" fill="white"/>
          <path d="M24 0C17.6 0 11.5 2.5 7 7.1C2.5 11.6 0 17.7 0 24.1C0 29.3 1.7 34.3 4.8 38.5C4.8 38.5 5.5 39.4 5.6 39.5L24 61.3L42.4 39.5C42.5 39.4 43.2 38.5 43.2 38.5C46.3 34.3 48 29.3 48 24.1C48 17.7 45.5 11.6 41 7.1C36.5 2.5 30.4 0 24 0ZM24 33C21.6131 33 19.3239 32.0518 17.636 30.364C15.9482 28.6761 15 26.3869 15 24C15 21.6131 15.9482 19.3239 17.636 17.636C19.3239 15.9482 21.6131 15 24 15C26.3869 15 28.6761 15.9482 30.364 17.636C32.0518 19.3239 33 21.6131 33 24C33 26.3869 32.0518 28.6761 30.364 30.364C28.6761 32.0518 26.3869 33 24 33Z" fill="#F33333"/>
        </svg>
      </div>
      <div class="tl-line tl-line--mobile"></div>
      <div class="tl-line__marker tl-line__marker--mobile">
        <svg width="48" height="62" viewBox="0 0 48 62" fill="none" xmlns="http://www.w3.org/2000/svg">
          <circle cx="24" cy="24" r="10" fill="white"/>
          <path d="M24 0C17.6 0 11.5 2.5 7 7.1C2.5 11.6 0 17.7 0 24.1C0 29.3 1.7 34.3 4.8 38.5C4.8 38.5 5.5 39.4 5.6 39.5L24 61.3L42.4 39.5C42.5 39.4 43.2 38.5 43.2 38.5C46.3 34.3 48 29.3 48 24.1C48 17.7 45.5 11.6 41 7.1C36.5 2.5 30.4 0 24 0ZM24 33C21.6131 33 19.3239 32.0518 17.636 30.364C15.9482 28.6761 15 26.3869 15 24C15 21.6131 15.9482 19.3239 17.636 17.636C19.3239 15.9482 21.6131 15 24 15C26.3869 15 28.6761 15.9482 30.364 17.636C32.0518 19.3239 33 21.6131 33 24C33 26.3869 32.0518 28.6761 30.364 30.364C28.6761 32.0518 26.3869 33 24 33Z" fill="#F33333"/>
        </svg>
      </div>
    </div>
    <div class="tl-section" data-index="tl-section-0">
      <div class="tl-section__bullet"></div>
      <div class="tl-section__line"></div>
      <div class="tl-section__content" data-orient="left">
        <div class="tl-section__text">
          <h3>Section Title</h3>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
        </div>
        <a class="btn--link btn--link-primary btn--link-sm" href="#">
          Test Link
        </a>
      </div>
      <div class="tl-section__image" data-orient="right">
        <img src="https://images.unsplash.com/photo-1661983228573-731da056ea20?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NjQ0MDk4MjE&ixlib=rb-1.2.1&q=80" alt="unify your data">
      </div>
    </div>
    <div class="tl-section" data-index="tl-section-1">
      <div class="tl-section__bullet"></div>
      <div class="tl-section__line"></div>
      <div class="tl-section__content" data-orient="right">
        <div class="tl-section__text">
          <h3>Section Title</h3>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
        </div>
        <a class="btn--link btn--link-primary btn--link-sm" href="//www-golimelight-com.sandbox.hs-sites.com/en/capabilities/planning-and-forecasting?hsLang=en">
          Test Link
        </a>
      </div>
      <div class="tl-section__image" data-orient="left">
        <img src="https://images.unsplash.com/photo-1661983228573-731da056ea20?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NjQ0MDk4MjE&ixlib=rb-1.2.1&q=80" alt="start manipulating your data">
      </div>
    </div>
    <div class="tl-section" data-index="tl-section-2">
      <div class="tl-section__bullet"></div>
      <div class="tl-section__line"></div>
      <div class="tl-section__content" data-orient="left">
        <div class="tl-section__text">
          <h3>Section Title</h3>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
        </div>
        <a class="btn--link btn--link-primary btn--link-sm" href="//www-golimelight-com.sandbox.hs-sites.com/en/capabilities/financial-reporting?hsLang=en">
          Test Link
        </a>
      </div>
      <div class="tl-section__image" data-orient="right">
        <img src="https://images.unsplash.com/photo-1661983228573-731da056ea20?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NjQ0MDk4MjE&ixlib=rb-1.2.1&q=80" alt="review your insights">
      </div>
    </div>
    <div class="tl-section" data-index="tl-section-3">
      <div class="tl-section__bullet"></div>
      <div class="tl-section__line"></div>
      <div class="tl-section__content" data-orient="right">
        <div class="tl-section__text">
          <h3>Section Title</h3>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
        </div>
        <a class="btn--link btn--link-primary btn--link-sm" href="//www-golimelight-com.sandbox.hs-sites.com/learning-library?hsLang=en">
          Test Link
        </a>
      </div>
      <div class="tl-section__image" data-orient="left">
        <img src="https://images.unsplash.com/photo-1661983228573-731da056ea20?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NjQ0MDk4MjE&ixlib=rb-1.2.1&q=80" alt="take action">
      </div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Signika+Negative:300,400&display=swap');

body { 
  font-family: "Signika Negative", sans-serif; 
  font-weight: 300;
  height: 5000px;
  margin: 0;
  padding: 0 20px;
}

h3 {
  font-size: 32px;
}

a {
  cursor: pointer;
  font-size: 16px;
  font-weight: 400;
  line-height: 2.1;
  color: #86CA45;
  text-decoration: none;
  margin-bottom: 0px;
}

.content-wrapper {
  width: 1240px;
  margin: 1000px auto;
}

.timeline {
  position: relative;
}

.tl-line-container {
  position: absolute;
  top: 0;
  left: 0;
  height: 0;
  width: auto;
  z-index: 1;
}

.tl-line {
  height: 100%;
  width: 2px;
  background: #86CA45;
  z-index: 1;
}

.tl-line--desktop {
  display: none;
}

.tl-line--mobile {
  display: block;
  margin: 0 0 0 9px;
}

.tl-line__marker--desktop {
  display: none;
}

.tl-line__marker--mobile {
  position: absolute;
  top: 0;
  left: 10px;
  transform: translate(-50%, -100%);
  z-index: 2;
}

.tl-section {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: start;
  align-items: start;
  gap: 32px;
  padding-left: 50px;
  margin-bottom: 64px;
  box-sizing: content-box;
}

.tl-section:last-child {
  margin-bottom: 0;
}

.tl-section__bullet {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 21px;
  width: 21px;
  background: #86CA45;
  border-radius: var(--border-radius-lg);
}

.tl-section__line {
  content: '';
  position: absolute;
  top: 10px;
  left: 10px;
  width: 2px;
  height: 0;
  transform: translateX(-50%);
  z-index: 0;
}

.tl-section__image img {
  max-width: 100%;
}

@media (min-width: 768px) {
  .tl-line-container {
    position: absolute;
    top: 0;
    left: 50%;
    height: 0;
    width: auto;
    transform: translateX(-50%);
    z-index: 1;
  }

  .tl-line--desktop {
    display: block;
    margin: 0 auto;
  }

  .tl-line--mobile {
    display: none;
  }
  
  .tl-line__marker--desktop {
    display: block;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translate(-50%, -100%);
    z-index: 2;
  }

  .tl-line__marker--mobile {
    display: none;
  }

  .tl-section {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 250px;
    padding-left: 0;
  }

  .tl-section__bullet {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  .tl-section__line {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2px;
    height: 0;
    transform: translateX(-50%);
  }

  .tl-section__content {
    width: 40%;
  }

  .tl-section__image {
    width: 40%;
  }

  [data-orient="left"] {
    order: 1;
  }

  [data-orient="right"] {
    order: 2;
  }
}
              
            
!

JS

              
                // gsap.to()... infinity and beyond!
// For more check out greensock.com

//================ MODEL ==================
const model = {
  body: document.querySelector('body'),

  getBodyWidth() {
    return this.body.clientWidth
  }
}

//================ CONTROLLER ==================
const controller = {
  timeline: document.querySelector('.timeline'),
  marker: document.querySelector('.tl-line__marker--desktop'),
  mobileMarker: document.querySelector('.tl-line__marker--mobile'),
  bulletArr: document.querySelectorAll('.tl-section__bullet'),
  sections: document.querySelectorAll('.tl-section'),
  bulletPos: [],
  linePos: {},
  masterTl: gsap.timeline(),

  init(width) {
    this.updateBulletPos()
    this.updateLinePos()
    view.setNewLinePos(width)
    // view.setMarkerPos()
    this.buildTimeLine(width)
  },

  updateBulletPos() {
    let timelineCoords = this.timeline.getBoundingClientRect(),
        timelineTop = timelineCoords.top,
        scrollPos = window.scrollY
  
    this.bulletPos = []

    this.bulletArr.forEach(bullet => {
      let coords = bullet.getBoundingClientRect()

      let bulletObj = {
        absoluteCenter : coords.top + (coords.height / 2) + scrollPos,
        relativeCenter : coords.top - timelineTop + (coords.height / 2)
      }
      this.bulletPos.push(bulletObj);
    })
  },

  updateLinePos() {
    let firstBullet = this.bulletPos[0]
    let lastBullet = this.bulletPos.findLast(el => el)

    this.linePos.top = firstBullet.relativeCenter
    this.linePos.height = lastBullet.relativeCenter - firstBullet.relativeCenter
    this.linePos.bottom = lastBullet.relativeCenter
  },

  buildTimeLine(width) {
    let length = this.sections.length

    console.log(this.sections, this.sections.length)
    for(let i = 0; i < length; i++) {
      let data = {
        section: {
          el: this.sections[i],
          bullet: this.bulletPos[i],
          contentLeft: this.sections[i].querySelector('[data-orient="left"'),
          contentRight: this.sections[i].querySelector('[data-orient="right"')
        },
        nextSection: {
          el: this.sections[i + 1],
          bullet: this.bulletPos[i + 1],
          contentLeft: null,
          contentRight: null
        }
      }
      
      console.log(data)
      let { section, nextSection } = data

      if (i < (length - 1)) {
        nextSection.contentLeft = this.sections[i + 1].querySelector('[data-orient="left"'),
        nextSection.contentRight = this.sections[i + 1].querySelector('[data-orient="right"')

        const line = section.el.querySelector('.tl-section__line')
        const lineHeight = nextSection.bullet.relativeCenter - section.bullet.relativeCenter
        const tl = gsap.timeline({scrollTrigger: {trigger: line, start: "top center", end: "bottom center", scrub: true}})
        gsap.set(line, {height: lineHeight})

        gsap.killTweensOf(tl)

        if(width > 767) {
          tl.to(section.contentLeft, {opacity: 0, x: -200, duration: 1, ease: 'none'});
          tl.to(section.contentRight, {opacity: 0, x: 200, duration: 1, ease: 'none'}, "<");
  
          tl.from(nextSection.contentLeft, {opacity: 0, x: -200, duration: 1, ease: 'none'}, "<");
          tl.from(nextSection.contentRight, {opacity: 0, x: 200, duration: 1, ease: 'none'}, "<");
        } else {

          tl.from(nextSection.contentLeft, {opacity: 0, x: 200, duration: 1, ease: 'none'});
          tl.from(nextSection.contentRight, {opacity: 0, x: 200, duration: 1, ease: 'none'}, "<");
        }

        this.masterTl.add(tl)

        console.log(this.masterTl)
      }
    }
  },

  resetTimeLine() {
    this.masterTl && this.masterTl.revert()
  },
}

//================ VIEW ==================
const view = {
  container: document.querySelector('.tl-line-container'),

  setNewLinePos(width) {
    let linePos = controller.linePos

    if(width > 767) {
      gsap.set(this.container, {top: linePos.top, height: linePos.height})
      console.log(linePos)
      ScrollTrigger.create({ trigger: this.container, start: "top center", end: "bottom center", pin: controller.marker, pinReparent: true })
    } else {
      gsap.set(this.container, {top: 9, height: linePos.height})
      ScrollTrigger.create({ trigger: this.container, start: "top center", end: "bottom center", pin: controller.mobileMarker })
    }
  },
}

const observer = new ResizeObserver(debounce(entries => {
  let newWidth = model.getBodyWidth()
  console.log(model.body.clientHeight, model.body.clientWidth)
  controller.resetTimeLine()
  controller.init(newWidth)
}, 500))

observer.observe(model.body)

function debounce(func, wait) {
	var timeout;
	return function() {
		var context = this, args = arguments;
		clearTimeout(timeout);
		timeout = setTimeout(function() {
		  func.apply(context, args);
    }, wait);
	};
}
              
            
!
999px

Console