Pango - Intro Animation

In this example below you will see how to do a Pango - Intro Animation with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by ElHalWaNY, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright ElHalWaNY ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title> Pango - Intro Animation </title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">

  <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/sanitize.css/2.0.0/sanitize.min.css'>
<link rel='stylesheet prefetch' href='https://fonts.googleapis.com/css?family=Lato:300'>

      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

   <section id="intro" class="section section--intro">
  <!-- mousemove event layer (for background effect) -->
  <div class="mouse-tracker-layer"></div>

  <div class="square-dark-wrapper">
    <div class="square-dark"></div>
  </div>

  <div class="pango-logo-group">
    <!-- Outer logo outline animation -->
    <svg class="outer-logo-circle" viewBox="0 0 700 700">
      <circle class="circle" fill="none" cx="350" cy="350" r="330"/>
    </svg>

    <!-- Pango SVG logo -->
    <svg class="pango-logo" viewBox="91 185 700 700" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
      <defs>
        <circle id="a" cx="350.5" cy="351" r="329"/>
        <mask id="b" x="-4" y="-4" width="666" height="666">
          <path fill="#fff" d="M17.5 18h666v666h-666z"/>
          <use xlink:href="#a"/>
        </mask>
        <path d="M183 154c-12.15 0-183-49-183-49L154 0s51 119.85 51 132c0 12.15-9.85 22-22 22z" id="d"/>
        <path d="M22 154c12.15 0 183-49 183-49L51 0S0 119.85 0 132c0 12.15 9.85 22 22 22z" id="f"/>
      </defs>
      <g fill="none" fill-rule="evenodd" transform="translate(91 185)">
        <circle cx="350" cy="350" r="350"/>
        <mask id="c" fill="#fff">
          <use xlink:href="#a"/>
        </mask>
        <use fill="#672F56" xlink:href="#a"/>
        <use stroke-opacity="0" stroke="#979797" mask="url(#b)" stroke-width="8" xlink:href="#a"/>
        <g mask="url(#c)">
          <path d="M667.8 262.12c-9.42-4.4-20.14-8.7-30.63-12.65 3.38-15.18 5.72-30.57 7-46.07 4.8-57-4.3-78.25-32.27-99.45-27.96-21.2-74.86-19.9-109.56-10.53-10.65 2.86-22.4 6.7-33.56 10.7-6.58-11.4-13.94-23.4-21-33.56-20.62-29.46-55.66-60.64-90.7-62.38-35.06-1.74-55.74 8.66-88.74 55.45-9 12.7-17.1 25.98-24.26 39.78-10.57-3.7-21.56-7.3-31.58-10-34.73-9.3-81.62-10.6-109.58 10.6-27.96 21.2-37.07 42.4-32.27 99.5 1.27 15.5 3.6 30.9 7 46.1-10.5 4-21.2 8.3-30.62 12.7-32.6 15.2-69.4 44.3-77.18 78.5-7.8 34.2-1.13 56.4 39.2 97C27.35 456 42 471.1 52.52 482.1c-3.14 14.3-5.35 28.76-6.63 43.33-5.2 57 3.8 78.3 31.7 99.66 27.8 21.3 94 24.2 128.7 15.1 34.7-9.2 59.1-31.6 59.1-31.6l176.3 5.7s48 20.3 84 29.7c36 9.4 84.5 10.6 113.4-11.6 28.8-22.1 38.1-44.1 32.8-103.1-1.4-16.3-4-32.5-7.7-48.4 9.8-10.9 23.5-25.7 41.3-43.6 40.3-40.6 47-62.7 39.2-96.9-7.8-34.2-44.6-63.3-77.2-78.5z" fill="#873158"/>
          <path d="M611.05 285.6c-6.66-3.07-14.07-6.08-21.52-8.92 2.44-11.6 4.2-23.33 5.23-35.14 4.43-49.2-3.3-67.42-27.23-85.55-23.93-18.2-64.28-16.8-94.2-8.5-7.52 2-15.68 4.7-23.7 7.5-5-8.6-10.33-17.3-15.54-24.8-17.7-25.6-47.7-52.6-77.6-54.1-30-1.5-47.7 7.5-75.9 48-6.8 9.7-13 19.8-18.6 30.3-7.6-2.6-15.2-5.1-22.2-7-29.9-8.2-70.3-9.7-94.2 8.5-24 18.1-31.7 36.3-27.2 85.5 1 11.8 2.7 23.5 5.2 35.1-7.5 2.8-14.9 5.8-21.5 8.9-28.2 12.9-60 37.8-66.7 67-6.7 29.3-.9 48.2 34.1 83 20 20 37.9 32.5 49.5 39.5-1.4 6.1-2.6 12.6-3.7 19.7-7.5 48.8-.9 67.5 21.9 87 22.7 19.6 63.1 20.44 93.5 14.1 30.3-6.33 71.4-21.4 71.4-21.4h110.8s41 15.1 71.3 21.44c30.3 6.32 70.7 5.33 93.5-14.25 22.7-19.57 29.3-38.2 21.8-87-1.2-7.4-2.5-14.3-3.9-20.67 11.6-7.2 28.7-19.47 47.9-38.5 35-34.9 40.8-53.8 34.1-83.05-6.7-29.26-38.5-54.1-66.7-67.05z" fill="#A83956"/>
          <path d="M555.53 308.96c-3.9-1.76-8.13-3.5-12.45-5.18 1.4-7.2 2.64-15.26 3.52-24.2 4.05-41.32-2.3-56.6-22.2-71.64-19.9-15.05-53.7-13.58-78.8-6.48-4.42 1.25-9.1 2.75-13.82 4.36-3.3-5.6-6.72-11.1-10.06-16-14.67-21.58-39.6-44.42-64.53-45.7-25-1.26-39.6 6.36-63.1 40.63-5.1 7.4-9.3 14.4-12.9 20.8-4.4-1.5-8.8-2.88-12.9-4-25.1-7.1-58.9-8.6-78.8 6.47-19.9 15.06-26.3 30.3-22.2 71.65.8 8.93 2.1 17 3.5 24.2-4.3 1.68-8.6 3.42-12.5 5.17-23.8 10.7-50.6 31.28-56.2 55.6-5.6 24.34-.7 40.1 29 69.17 10.4 10.3 21.7 19.6 33.8 27.9-1.7 5.8-3.2 12-4.6 18.8-8.4 40.7-3.6 56.6 14.6 73.6 18.2 17.1 52 19.3 77.7 14.9 25.7-4.4 60.6-15.6 60.6-15.6H402s53.6 14.4 60.7 15.6c25.7 4.5 59.44 2.3 77.7-14.7 18.22-17 23-32.9 14.6-73.6-1.47-7.2-3.14-13.8-4.9-19.9 11.5-7.9 22.3-16.9 32.27-26.7 29.6-29.1 34.6-44.8 29-69.2-5.6-24.3-32.4-44.9-56.2-55.6z" fill="#C34057"/>
          <path d="M497.6 332.45c-1.1-.5-2.27-1-3.46-1.46.72-4.2 1.36-8.6 1.88-13.3 3.68-33.5-1.28-45.8-17.17-57.8-15.9-12-43.12-10.5-63.4-4.5l-3.93 1.2c-1.53-2.6-3.08-5-4.6-7.3-11.7-17.6-31.56-36.3-51.43-37.4-19.9-1.1-31.6 5.2-50.3 33.2-2.7 3.9-5 7.7-7.1 11.3-1.2-.4-2.4-.8-3.6-1.1-20.3-6-47.5-7.6-63.4 4.4-15.9 12-20.9 24.2-17.2 57.7.5 4.7 1.1 9.1 1.9 13.2-1.2.42-2.4 1-3.5 1.4-19.4 8.42-41.3 24.8-45.7 44.14-4.5 19.4-.4 32 24 55.3 7 6.8 14.6 13.1 22.5 18.8-1.5 4.9-2.9 10.23-4.1 16.1-7 32.94-3.3 45.65 11.3 59.16 14.6 13.5 41.8 14.6 62.6 10.6 20.8-3.9 49.1-13.7 49.1-13.7h47.4s32.4 10.6 49.1 13.7c20.8 4 48 2.87 62.6-10.64 14.6-13.5 18.3-26.2 11.3-59.13-1.4-6.3-2.9-12-4.4-17.18 7.4-5.44 14.4-11.36 21-17.7 24.3-23.2 28.4-35.8 23.9-55.2-4.47-19.4-26.3-35.7-45.7-44.17z" fill="#E14756"/>
          <g transform="translate(134 527)">
            <mask id="e" fill="#fff">
              <use xlink:href="#d"/>
            </mask>
            <path d="M149.34 22.85l16.63-.86 48.8 134s-51.8-62-93.7-110.7c.4-.8.8-1.7 1.27-2.5 6.35-11.8 18.9-17.7 27-20z" fill="#C3C3C3" mask="url(#e)"/>
            <path d="M115 44.65c1.84.33 3.8.8 5.74 1.33l.3-.6c41.93 48.7 93.7 110.65 93.7 110.65s-84.72-33.83-138.5-70.6c2.08-17.78-.82-25 7.53-32.82 8.35-7.8 22.93-9.4 31.23-7.9z" fill="#AAA" mask="url(#e)"/>
            <path d="M55.87 97.54c3-4.9 20.2-10.85 20.35-12.1 53.8 36.77 138.52 70.6 138.52 70.6s-96.9-.96-159.53-39.5c-.5-1.03-2.7-13.55.7-19z" fill="#909090" mask="url(#e)"/>
          </g>
          <g transform="translate(365 527)">
            <mask id="g" fill="#fff">
              <use xlink:href="#f"/>
            </mask>
            <path d="M54.4 24.86l-16.6-.83-48.8 134S40.8 96.1 82.7 47.4c-.44-.83-.8-1.66-1.3-2.54-6.34-11.73-18.9-17.67-27-20z" fill="#C3C3C3" mask="url(#g)"/>
            <path d="M88.75 46.65c-1.84.33-3.8.8-5.74 1.33l-.3-.6C40.8 96.1-11 158.04-11 158.04s84.73-33.83 138.52-70.6c-2.1-17.78.8-25-7.54-32.82-8.35-7.8-22.93-9.4-31.23-7.95z" fill="#AAA" mask="url(#g)"/>
            <path d="M147.88 99.54c-3-4.9-20.2-10.85-20.35-12.1C73.73 124.2-11 158.04-11 158.04s97.56-3.63 160.2-42.18c.58-1.02 2.06-10.84-1.32-16.33z" fill="#909090" mask="url(#g)"/>
          </g>
          <path d="M473.6 388.62c-3-12.73-16.14-23.6-29.55-30.27.12-.83.37-1.64.48-2.5 3.3-25.62-.2-34.93-12.07-43.83-9-6.72-22.9-7.46-35.85-5.32-8.8-12.94-22.7-25.86-36.7-26.62-14.8-.8-23.5 4-37.4 25.8-.8 1.27-1.6 2.52-2.3 3.76-15.6-4.9-36.3-6.48-48.1 2.43-11.8 8.9-15.4 18.16-12.1 43.8.1.84.3 1.65.4 2.48-13.4 6.65-26.8 17.53-29.8 30.27-1.9 8.27-1.6 14.9 2.5 22.33 16.6 44.65 75 181.64 75 181.64 7.6 16.2 25.5 31.8 44.4 31.8 21.8 0 39-19.4 44.4-34.2 0 0 59.2-136.7 75.3-179.6 1.2-2.5 2-5.1 2.4-7.9 1.5-4.5.6-9-.6-14.3z" fill="#F67958"/>
        </g>
      </g>
    </svg>
    <div class="square-wrapper">
      <div class="line"></div>
      <div class="line"></div>
      <div class="line"></div>
      <div class="line"></div>
    </div>
    <div class="sparks">
      <svg class="spark" viewBox="91 -1 94 94" xmlns="http://www.w3.org/2000/svg">
        <path d="M184 92c0-50.8-41.2-92-92-92" stroke="#f0f0f0" fill="none"/>
      </svg>
      <svg class="spark" viewBox="91 -1 94 94" xmlns="http://www.w3.org/2000/svg">
        <path d="M184 92c0-50.8-41.2-92-92-92" stroke="#f0f0f0" fill="none"/>
      </svg>
    </div>
  </div>

  <h1 class="pango-words">
    <span class="pango-word">PANGO</span>
    <div class="line-separator"></div>
    <span class="pango-word">INTERACTIVE</span>
  </h1>

  <div class="bg-lines-wrapper"></div>
</section>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.13.1/lodash.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenMax.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/ElHalWaNY/pango-intro-animation-qaxGbN */
.absolute-center,
.square-wrapper,
.square-dark-wrapper,
.sparks,
.pango-logo-group,
.pango-logo,
.pango-words,
.outer-logo-circle {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  margin: auto;
}
.section {
  position: relative;
  width: 100%;
  min-height: 100vh;
}
.section--intro {
  overflow: hidden;
}
html,
body {
  width: 100%;
  min-height: 100%;
  background: #f0f0f0;
  overflow-x: hidden;
}
.wrapper {
  width: 960px;
  height: 100%;
  margin: auto;
  z-index: 14;
  position: relative;
}
.square-wrapper {
  width: 200px;
  height: 200px;
  background: #f0f0f0;
}
.line {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  width: 100%;
  height: 4px;
  background: #1e1e20;
}
.line:nth-child(3) {
  top: auto;
  bottom: 0;
}
.line:nth-child(2),
.line:nth-child(4) {
  top: 50%;
  left: -50%;
  margin-top: -2px;
  -webkit-transform: rotate(90deg);
  transform: rotate(90deg);
}
.line:nth-child(2) {
  left: 50%;
}
.square-dark-wrapper {
  width: 0;
  height: 0;
  will-change: transform;
  -webkit-transform: scale(0);
  transform: scale(0);
}
.square-dark {
  background: #1e1e20;
  border-radius: 50%;
  -webkit-transform: translateX(-50%) translateY(-50%);
  transform: translateX(-50%) translateY(-50%);
}
.sparks {
  width: 100px;
  height: 100px;
}
.spark {
  -webkit-transform: rotate(45deg);
  transform: rotate(45deg);
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  right: -200%;
  will-change: stroke-dashoffset;
  stroke-dasharray: 145;
  stroke-dashoffset: -145;
}
.spark:last-child {
  left: -200%;
  right: auto;
  -webkit-transform: rotate(-135deg);
  transform: rotate(-135deg);
}
.pango-logo-group {
  margin-top: -5rem;
  z-index: 15;
}
.pango-logo {
  width: 190px;
  height: 190px;
  z-index: 16;
  opacity: 0;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
  filter: alpha(opacity=0);
  -webkit-transform: scale(0.9);
  transform: scale(0.9);
}
.pango-words {
  width: 190px;
  height: 120px;
  font-family: 'Lato';
  font-size: 3rem;
  font-weight: 300;
  color: #f0f0f0;
  top: auto;
  bottom: 10%;
  overflow: hidden;
  will-change: opacity;
}
.pango-words .line-separator {
  width: 90%;
  height: 1px;
  background: #f0f0f0;
  will-change: transform;
  margin: 0.2em auto;
}
.pango-word {
  text-align: center;
  display: block;
  overflow: hidden;
  line-height: 1;
}
.pango-word span {
  will-change: transform;
  display: inline-block;
}
.pango-word:last-of-type {
  letter-spacing: 0.11em;
  font-size: 1.4rem;
  font-weight: 100;
}
.outer-logo-circle {
  width: 190px;
  height: 190px;
  z-index: 14;
  -webkit-transform-origin: 50% 50%;
  transform-origin: 50% 50%;
  -webkit-transform: rotate(-90deg) scale(0.9);
  transform: rotate(-90deg) scale(0.9);
}
.outer-logo-circle .circle {
  -webkit-transform: translateZ(1px);
  transform: translateZ(1px);
  stroke: #1e1e20;
  stroke-dasharray: 2072;
  stroke-dashoffset: 2072;
  stroke-width: 16px;
}
.bg-lines-wrapper {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 10;
  will-change: transform;
  -webkit-transform: perspective(1000px) rotateX(45deg);
  transform: perspective(1000px) rotateX(45deg);
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
}
.bg-lines-wrapper .line {
  position: absolute;
  top: 0;
  left: 0;
  background: rgba(255,255,255,0.2);
  width: 2px;
  height: 2px;
  -webkit-transform: scaleX(0);
  transform: scaleX(0);
  -webkit-transform-origin: 0 50%;
  transform-origin: 0 50%;
}
.mouse-tracker-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 18;
}
.top-nav {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 19;
}
.nav-list {
  list-style: none;
  padding: 1rem 2rem;
}
.nav-list--item {
  display: inline-block;
}
.nav-list--item a {
  color: #f0f0f0;
  padding: 0.4rem;
  margin: 0 0.4rem;
  display: block;
  text-transform: uppercase;
  text-decoration: none;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}
.nav-list--item a:hover {
  border-color: currentColor;
}


/*Downloaded from https://www.codeseek.co/ElHalWaNY/pango-intro-animation-qaxGbN */
// Replaces the element text with an array of spans
// and returns it
function splitTextInSpans(elem) {
  const letters = elem.textContent.split('')
  elem.innerHTML = ''
  return letters.map(letter => {
    const span = document.createElement('span')
    span.textContent = letter
    elem.appendChild(span)
    return span
  })
}

function intro() {
  function animateLogo(tl) {
    const maxWindowSize = Math.max(window.innerHeight, window.innerWidth)

    const squareDarkWrapper = document.querySelector('.square-dark-wrapper')
    const squareDark = squareDarkWrapper.querySelector('.square-dark')

    const square = document.querySelector('.square-wrapper')
    const lines = square.querySelectorAll('.line')

    const sparks = document.querySelectorAll('.spark')
    const outerCircle = document.querySelector('.outer-logo-circle .circle')
    const logo = document.querySelector('.pango-logo')

    tl.set(squareDark, {
        height: maxWindowSize,
        width: maxWindowSize
      })
      .set(lines, { scaleX: 0 })

    _.forEach(lines, (line, i) => {
      tl.to(lines[i], 2, {
        scaleX: 1,
        ease: 'Expo.easeOut'
      }, i / 10)
    })

    tl.to(lines, .05, {
        opacity: 0
      }, 1)
      .to(squareDarkWrapper, 1.5, {
        scale: 1.4,
        ease: 'Expo.easeOut'
      }, 1)
      .to(square, 2, {
        rotationZ: 45,
        ease: 'Expo.easeOut'
      }, 1.5)
      .to(sparks, 1, {
        strokeDashoffset: 0,
        ease: 'Expo.easeOut'
      }, 1.5)
      .to(sparks, 1, {
        strokeDashoffset: 145,
        ease: 'Expo.easeOut'
      }, 1.5)
      .to(outerCircle, 1.4, {
        strokeDashoffset: 0,
        ease: 'Expo.easeInOut'
      }, 1.7)
      .to(outerCircle, .4, {
        opacity: 0,
        ease: 'Power4.easeOut'
      }, 2.7)
      .to(logo, 1, {
        opacity: 1,
        scale: 1,
        ease: 'Power4.easeOut'
      }, 2.7)

    return tl
  }

  function animateWords(tl) {
    const wordsWrapper  = document.querySelector('.pango-words')
    const words         = wordsWrapper.querySelectorAll('.pango-word')
    const lineSeparator = wordsWrapper.querySelector('.line-separator')

    tl.set(lineSeparator, { scaleX: 0 })
      .to(lineSeparator, 1, {
        scaleX: 1,
        ease: 'Expo.easeOut'
      }, 3)

    _.forEach(words, word => {
      const spans = splitTextInSpans(word)
      _.forEach(spans, (span, j) => {
        let tlWords = new TimelineMax()

        tlWords.set(span, { y: span.clientHeight, opacity: 1 })
        const delay = (3 + ((Math.abs(spans.length / 2 - j)) / 20)).toFixed(2)
        tlWords.to(span, 1.4, {
          y: 0,
          ease: 'Expo.easeOut'
        }, delay)
      })
    })
    return tl
  }

  function animateBackground(tl) {
    const wrapper = document.querySelector('.bg-lines-wrapper')
    const createLines = qty => {
      for (let i = 0; i < qty; i++) {
        const line = document.createElement('div')
        line.classList.add('line')
        wrapper.appendChild(line)
        tl.set(line, {
            x: _.random(window.innerWidth),
            y: _.random(window.innerHeight),
            z: _.random(-200, 200),
            width: _.random(0, 100) + 50,
            scaleX: 0
          })
      }
    }

    function animateLines(lines) {
      for (let line of lines) {
        const startTime = _.random(5, true)
        tl.to(line, .4, {
            scaleX: 1,
            ease: 'Expo.Power4'
          }, startTime)
          .to(line, 2, {
            scaleX: 0,
            x: '+=' + line.style.width,
            ease: 'Power4.easeOut'
          }, startTime + .4)
      }

      // 3d rotation
      const rotate = (rx, ry) => {
        TweenMax.to(wrapper, .75, {
            rotationX: ry,
            rotationY: rx,
            ease: 'Power0.easenone'
          })
      }

      // update rotation values
      function update(elem, event, tilt) {
        if (tilt) {
          const tiltLR = event.gamma
          const tiltFB = event.beta
          rotate(tiltLR / 1.5, tiltFB / 1.5)

          return
        }

        const xpos = event.layerX || event.offsetX
        const ypos = event.layerY || event.offsetY

        const ax = -(window.innerWidth / 2 - xpos) / 40
        const ay = (window.innerHeight / 2 - ypos) / 10
        rotate(ax, ay)
      }

      // get element for mousemove event tracking
      // on top of all other layers
      const trackerLayer = document.querySelector('.mouse-tracker-layer')
      trackerLayer.addEventListener('mousemove', e => window.requestAnimationFrame(() => update(wrapper, e)))

      if (window.DeviceOrientationEvent) {
        window.addEventListener('deviceorientation', e =>
          window.requestAnimationFrame(() => update(wrapper, e, true)))
      }
    }

    createLines(50)
    animateLines(wrapper.querySelectorAll('.line'))
  }

  return {
    animateLogo,
    animateWords,
    animateBackground
  }
}

/*intro().animateBackground(new TimelineMax({
  delay: 2.8,
  repeat: -1,
  repeatDelay: 0
}))*/
intro().animateLogo(new TimelineMax())
intro().animateWords(new TimelineMax())

Comments