css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="Wave-container">
  <div class="Wave"></div>
</div>
            
          
!
            
              $global-border-radius: 3px;
$global-contrast: #fff;
$global-disabled-opacity: 0.5;
$global-font-size-small: 14px;
$global-primary: #0080ff;
$global-whitespace--xsmall: 4px;
$global-whitespace--small: 8px;
$global-whitespace--regular: 16px;
$global-whitespace--large: 32px;


html {
  height: 100%;
}
body {
  font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Open Sans","Helvetica Neue",sans-serif;
  letter-spacing: 0;
  font-weight: 400;
  font-style: normal;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -moz-font-feature-settings: "liga" on;
  color: #a8a8a8;
  font-size: 16px;
  line-height: 1.4;
  min-height: 100%;
  box-sizing: border-box;
  
  // For wave overflow
  overflow-x: hidden;
  
  *, *:before, *:after {
    box-sizing: inherit;
  }
}

img {
  max-width: 100%;
}

.Wave {

  &-container {
    max-width: 1400px;
    position: relative;
    overflow-x: hidden;
    margin: 0 auto;
    padding: 0 $global-whitespace--regular;
  }
}

.Employee {
  display: inline-block;
  position: absolute;
  //will-change: transform;

  &-tooltip {
    font-size: $global-font-size-small;
    text-align: center;
    white-space: nowrap;
    padding: $global-whitespace--small $global-whitespace--regular;
    background: $global-primary;
    color: $global-contrast;
    border-radius: $global-border-radius;
    position: absolute;
    left: 50%;
    top: 0;
    margin-top: ((-$global-whitespace--regular) + (-$global-whitespace--xsmall));
    pointer-events: none;
    transform: translate(-50%, -100%) scale(.5);
    transform-origin: center bottom;
    opacity: 0;

    &:after {
      content: '';
      width: 0;
      height: 0;
      position: absolute;
      bottom: -($global-whitespace--small - 1);
      left: 50%;
      transform: translate(-50%, 0);
      border-left: ($global-whitespace--small - 1) solid transparent;
      border-right: ($global-whitespace--small - 1) solid transparent;
      border-top: ($global-whitespace--small - 1) solid $global-primary;
    }
  }

  &:hover {
    z-index: 3;
  }

  &-name {
    font-weight: bold;
  }

  &-title {
    opacity: $global-disabled-opacity;
  }

  &-avatarCircle {
    border-radius: 50%;
    position: relative;
    overflow: hidden;
    width: 40px;
    height: 40px;
    //will-change: transform;

    &:after {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      border: 3px solid $global-primary;
      border-radius: 50%;
    }
  }

  &-avatar {
    border-radius: 50%;
    background-blend-mode: lighten;
    background-color: $global-primary;
    background-position: 50% 50%;
    background-size: cover;
    position: absolute;
    top: 1px;
    left: 1px;
    right: 1px;
    bottom: 1px;
    opacity: 0;
    z-index: 2;
  }

  &-avatarFill {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 50%;
    background: $global-primary;
    z-index: 1;
    opacity: 0;
  }
}
            
          
!
            
              document.addEventListener("DOMContentLoaded", function() {
  
  // Loop over DOM nodes
  function forEach(array, callback, scope) {
    for (let i = 0, arrayLength = array.length; i < arrayLength; i++) {
      callback.call(scope, i, array[i]); // passes back stuff we need
    }
  };
  
  // Return random number between two values
  function randomIntFromInterval(min, max) {
    return Math.floor(Math.random()*(max-min+1)+min);
  };

  // Return random float between two values
  function randomFloatFromInterval(min, max) {
    return (Math.random() * (max - min) + min).toFixed(4);
  };

  const points = 250; // Number of employees (would be brought in automatically from page)
  const $wave = document.querySelector('.Wave');
  const bezierCurve = [{x:0, y:25}, {x:350, y:25}, {x:750, y:250}, {x:1000, y:400}, {x:1400, y:400}];
  const easing = Power0.easeNone;
  const docfrag = document.createDocumentFragment();
  let bigY = 0; // Placeholder for finding largest Y coordinate so we can make our wave tall enough for mousemove listeners

  $wave.timeline = new TimelineMax({ paused: true });


  const testEmployee = {
    'name': 'Sammy The Shark',
    'title': 'Mascot',
    'avatar': 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-194/sammy.png'
  };

  for (let i = 0; i < points; i++) {
    const scale = randomFloatFromInterval(0.35, 0.50);
    let randomY;
    // Random spread for y values on alternating even/odd "i" count
    if (i % 2 === 0) {
      randomY = randomIntFromInterval(0, 150);
    }
    else {
      randomY = randomIntFromInterval(170, 320);
    }
    if (randomY > bigY) {
      bigY = randomY;
    }

    const point = document.createElement('div');
    point.style.top = `${randomY}px`;
    point.style.opacity = 0;
    point.classList.add('Employee');
    point.id = `Employee-${i}`;
    point.innerHTML = `<div class="Employee-tooltip">
                        <div class="Employee-name">${testEmployee.name}</div>
                        <div class="Employee-title">${testEmployee.title}</div>
                      </div>
                      <div class="Employee-avatarCircle">
                        <div class="Employee-avatarFill"></div>
                        <div class="Employee-avatar" style="background-image:url('${testEmployee.avatar}')"></div>
                      </div>`;

    // Setup GSAP Timeline
    point.waveTimeline = new TimelineMax({paused: true});

    TweenMax.set(point.querySelector('.Employee-avatarCircle'), {
      scale: scale
    });

    point.waveTimeline
    .to(point.querySelector('.Employee-avatarFill'), 0.25, {
      opacity: 1
    })
    .to(point.querySelector('.Employee-avatar'), 0.25, {
      opacity: 1,
      ease: easing
    });

    point.hoverTimeline = new TimelineMax({paused: true});

    point.hoverTimeline
    .to(point.querySelector('.Employee-avatarCircle'), 0.20, {
      scale: 1.25,
      ease: easing
    }, "hover")
    .to(point.querySelector('.Employee-tooltip'), 0.15, {
      delay: 0.15,
      opacity: 1,
      scale: 1,
      ease: easing
    }, "hover");

    $wave.timeline.add(pathTimeline(point, i), 0);

    docfrag.appendChild(point);
  }

  // Bezier path for each point
  function pathTimeline(point, i) {
    const tl = new TimelineMax({
      repeat: -1,
      repeatDelay: (points * 0.35 - 24)
    });

    tl
    .delay((i * 0.35))
    .to(point, 1.5, {
      opacity: 1,
      ease: easing
    }, 'path')
    .to(point, 24, {
      bezier: {
        type: 'soft',
        values: bezierCurve
      },
      ease: easing
    }, 'path')
    .to(point, 1.5, {
      opacity: 0,
      delay: 20,
      ease: easing
    }, 'path');

    return tl;
  }

  $wave.appendChild(docfrag);

  const containerHeight = (bigY + 440 + 'px'); // extra `40` is to account for avatar size (CSS)

  // Set height of containers
  function setContainerHeight() {
    // Set `.Wave` to height of tallest coordinate for proper spacing
    $wave.parentNode.style.height = containerHeight;
    $wave.style.height = containerHeight;
  }

  // Kick-off animation
  function animationSequence() {
    // Set timeline to start 20 seconds in so we have a wave shape already
    $wave.timeline.time(20);
    $wave.timeline.play();
    // Set container height
    setContainerHeight();
  }
  animationSequence();

  const employees = $wave.querySelectorAll('.Employee');

  // Pause timeline on mouseenter
  $wave.addEventListener('mouseenter', () => {
    TweenMax.to($wave.timeline, 1, {
      timeScale: 0
    });
  }, false);

  // Play timeline on mouseleave
  $wave.addEventListener('mouseleave', () => {
    TweenMax.to($wave.timeline, 1, {
      timeScale: 1
    });

    // Make sure we set each employee tween back to the beginning
    forEach(employees, (index, value) => {
      value.waveTimeline.tweenTo(0);
    });
  }, false);

  // Hover animation calls
  forEach(employees, (index, value) => {
    // Add mouseover event listeners for targeted GSAP hover animation
    value.addEventListener('mouseenter', (e) => {
      e.preventDefault();

      value.waveTimeline.pause();
      value.hoverTimeline.play();
    }, false);
    
    value.addEventListener('mouseleave', (e) => {
      e.preventDefault();

      value.waveTimeline.resume();
      value.hoverTimeline.reverse();
    }, false);
  });

  // Mousemove listener
  let currX = -9999;
  let lastX = 0;
  let employeeHover = false;
  $wave.addEventListener('mousemove', (e) => {
    e.preventDefault();

    currX = (e.layerX - 16);
    employeeHover = e.target.closest('.Employee') ? true : false;

    //console.log(currX);
  }, false);

  function updateEmployees() {
    // Make sure we're inside the wave
    if (currX >= 0 && currX <= $wave.offsetWidth && lastX !== currX && !employeeHover) {
      // Test each node's coordinates relevant to mouse X position
      forEach(employees, (index, value) => {

        const offset = (value.getBoundingClientRect().left - $wave.getBoundingClientRect().left);

        // Determine tweenTo() %
        const distance = Math.abs(currX - offset);

        // We're burning hot!
        if (distance <= 90 ) {
          value.waveTimeline.tweenTo(value.waveTimeline.duration());
        }
        // We're pretty close
        else if (distance <= 180) {
          const multiplier = ((distance - 90) / 100);
          value.waveTimeline.tweenTo(value.waveTimeline.duration() * multiplier);
        }
        // Nada
        else {
          value.waveTimeline.tweenTo(0);
        }

      });

      // Update last X coordinate to ensure we don't check needlessly
      lastX = currX;

    }

    requestAnimationFrame(updateEmployees);
  }
  updateEmployees();

});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console