123

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.

            
              <!-- Keeping my skills sharp by putting together dribbble shots I find. This one comes from Tubik Studios. https://dribbble.com/shots/6691110-Ecommerce-Website-Interactions-Tubik -->
<div class="main-body loading">
  <div id="loader"></div>

  <nav class="navigation" id="navigation">
    <a class="navigation__logo" id="logo" href="https://dribbble.com/shots/6691110-Ecommerce-Website-Interactions-Tubik" target="_blank"><h1>STUDIO V.</h1></a>
    <div class="navigation__links" id="links">
      <ul>
        <li><a href="#">Collections</a></li>
        <li><a href="#">Blog</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Stores</a></li>
        <li><a href="#">Search</a></li>
      </ul>
      <ul>
        <li>Cart</li>
        <li>
          <div class="navigation__burger">
            <div></div>
            <div></div>
            <div></div>
          </div>
        </li>
      </ul>
    </div>
  </nav>

  <main id="container" data-scroll>
    <section class="fixed-header">
      <h1 class="fixed-header__headline back-index" id="top-headline">Ode to</h1>
      <h1 class="fixed-header__headline front-index" id="bottom-headline">Simplicity</h1>

      <div class="fixed-header__image-container" id="fixed-image-container">
        <div class="fixed-header__image-overflow" id="image-one-overflow">
            <img class="fixed-header__image" id="fixed-image" src="https://res.cloudinary.com/dleusut0r/image/upload/v1566299956/2.jpg" />
        </div>
        <div id="image-two-overflow">
          <img class="fixed-header__image-two" id="image-two" src="https://res.cloudinary.com/dleusut0r/image/upload/v1566299943/8.jpg" />
        </div> 
      </div>

      <div class="fixed-header__text" id="text">
        <p class="fixed-header__author">FRAME BY RELVAOKELLERMANN</p>
        <p class="fixed-header__subheadline">Designed to make certain areas of your life a little better, focused, and refined.</p>
        <a href="#">SHOP <span>→</span></a>
      </div>
    </section>

    <section class="right-image" id="right-image" data-scroll-section>
      <div class="right-image__overflow">
          <div class="right-image__container" style="background-image: url('https://res.cloudinary.com/dleusut0r/image/upload/v1566299964/1.jpg');"></div>
      </div>
    </section>

    <section class="description" id="description" data-scroll-section>
      <div class="description__container">
          <h1>Summer Essentials</h1>
          <p>Designed to simply share a handful of minimalist products to make certain areas of your life a little better, focused and refined. The first collection to help with summertime pursuits many of us experience this time of year.</p>
          <a href="#">COLLECTION -></a>
      </div>
    </section>

    <section class="sign-up" data-scroll-section>
      <div class="sign-up__container">
        <h1>DON'T MISS NEW RELEASES &amp; SUBSCRIBE EXCLUSIVES</h1>
        <h3>Sign up to receive updates</h3>
        <p>You can unsubscribe at any time</p>
        <form action="/" method="post">
          <input type="email" placeholder="EMAIL">
          <input type="submit" value="SUBSCRIBE">
        </form>
      </div>
    </section>
  </main>
  
    <div class="mobile-message"><h1>This is a desktop only experience</h1></div>
  
</div>
            
          
!
            
              .main-body, html {
  font-family: sans-serif;
  -webkit-font-smoothing: antialiased;
  margin: 0;
  padding: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

.main-body {
  overflow: hidden;
}

.main-body.is-mobile {
  overflow: auto;
}

.main-body.loading #loader {
    opacity: 1;
    transition: opacity 5s ease-out;
}

#loader {
  width: 100%;
  height: 100%;
  background-color: #ffe55d;
  position: fixed;
  top: 0;
  left: 0;
  opacity: 0;
  pointer-events: none;
  z-index: 100;
}

#percentage {
  position: absolute;
  transform: translate(-50%, -50%);
  left: 50%;
  top: 50%;
  font-size: 100px;
  margin: 0;
}

.navigation {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 200;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 30px 60px 0;
  box-sizing: border-box;
}

.navigation a {
  color: black;
  text-decoration: none;
}

.navigation h1,
.navigation ul {
  margin: 0;
  padding: 0;
}

.navigation__logo {
  font-size: 16px;
}

.navigation__links {
  display: flex;
  align-items: center;
  font-size: 14px;
}

.navigation__links ul {
  display: flex;
  align-items: center;
  list-style: none;
}

.navigation__links ul:first-child {
  margin-right: 100px;
}

.navigation__links li {
  margin-right: 50px;
  cursor: pointer;
}

.navigation__links li:last-child {
  margin-right: 0px;
}

.navigation__burger{
  position: relative;
  top: 2px;
  width: 30px;
  height: 30px;
  display: flex;
  flex-flow: column;
  align-items: center;
  justify-content: center;
}

.navigation__burger div{
  width: 15px;
  height: 2px;
  background-color: black;
  position: absolute;
}

.navigation__burger div:first-child{
  top: 10px;
}

.navigation__burger div:last-child{
  bottom: 10px;
}

.navigation__burger div:nth-child(2){
  transform: translate(0%, -50%);
  top: 50%;
}

[data-scroll] {
  position: fixed;
  z-index: 100;
  width: 100%;
  top: 0;
  left: 0;
  overflow: hidden;
  background-color: #ffe55d;
}

.main-body.is-mobile [data-scroll] {
  overflow: auto;
  position: relative;
  will-change: inherit;
}

.fixed-header {
  position: fixed;
  top: 0;
  width: 100%;
  padding: 100px 0 0 60px;
}

.fixed-header__headline {
  font-size: 150px;
  line-height: 150px;
  margin: 0 0 0 100px;
  position: relative;
  z-index: 1;
}

.fixed-header__headline.front-index {
  z-index: 3;
  margin-bottom: 35px;
}

.fixed-header__image-container {
  position: absolute;
  right: 0;
  top: 210px;
  z-index: 2;
  overflow: hidden;
}

.fixed-header__image-overflow {
  width: 80vw;
  padding-bottom: 42.5%;
  overflow: hidden;
}

.fixed-header__image {
  width: 100%;
  position: absolute;
}

.fixed-header__image-two {
  width: 100%;
  position: absolute;
}

.fixed-header__text {
  position: relative;
  z-index: 3;
}

.fixed-header__author {
  font-size: 11px;
  letter-spacing: 2px;
}

.fixed-header__subheadline {
  font-size: 24px;
  max-width: 412px;
  letter-spacing: -1px;
}

.right-image {
  width: 550px;
  position: relative;
  margin-left: auto;
  margin-top: 140px;
  margin-bottom: -200px;
  z-index: 1;
}

.right-image__overflow {
  overflow: hidden;
  transform-origin: top;
}

.right-image__container{
  width: 100%;
  padding-bottom: 125%;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  transform-origin: top;
}

.right-image.test .right-image__overflow {
  transform: scaleY(.25);
}

.right-image.test .right-image__container {
  transform: scaleY(2);
}

.description {
  position: relative;
  display: inline-block;
  margin: 0 225px 0 auto;
  float: right;
}

.description__container {
  background-color: #006def;
  color: white;
  padding: 60px;
  width: 400px;
}

.description h1 {
  font-size: 65px;
  line-height: 65px;
  margin: 0 0 35px;
}

.description p {
  font-size: 24px;
  line-height: 29px;
  letter-spacing: -1px;
}

.description a {
  display: block;
}

.sign-up {
  width: 768px;
  clear: both;
}

.sign-up__container {
  width: 100%;
  background-color: #ff191c;
  color: white;
  padding: 100px 80px;
}

.sign-up h1 {
  font-size: 100px;
  line-height: 100px;
  margin: 0 0 50px;
}

.sign-up h3 {
  font-size: 49px;
  margin: 0 0 25px;
}

.sign-up p {
  font-size: 30px;
}

.sign-up form {
  width: 700px;
  border-bottom: 2px solid white;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sign-up input[type=email] {
  background-color: transparent;
  color: white;
  border: none;
  width: 75%;
  padding: 10px 0;
}

.sign-up input[type=email]::placeholder {
  color: white;
  font-size: 15px;
}

.sign-up input[type=submit] {
  background-color: transparent;
  color: white;
  border: none;
  font-size: 15px;
  font-weight: bold;
  padding: 0;
  cursor: pointer;
}


.mobile-message {
  background-color: #ffe55d;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 30px;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 100vw;
  z-index: 999;
 display: none;
}

@media (max-width: 768px) {
  .mobile-message {
    display: block;
  }
}
            
          
!
            
              const support = {
  mobile: isMobile.any,
  firefox: navigator.userAgent.indexOf('Firefox') > -1
};

const math = {
  normalize: (value, max, min) => (value - min) / (max - min),
  denormalize: (value, max, min) => value * (max - min) + min,
  lerp: (previous, current, ease) => (1 - ease) * previous + ease * current,
  clamp: (min, max, value) => Math.max(min, Math.min(value, max))
};

const config = {
  windowWidth: window.innerWidth,
  windowHeight: window.innerHeight
};

const keyCodes = {
  LEFT: 37,
  UP: 38,
  RIGHT: 39,
  DOWN: 40,
  SPACE: 32
};

/**
 * https://gist.github.com/gre/1650294
 * https://easings.net/en
 **/
const ease = {
  // acceleration until halfway, then deceleration
  inOutQuad: t => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t),
  // decelerating to zero velocity
  outQuint: t => 1 + --t * t * t * t * t,
  // acceleration until halfway, then deceleration
};

class ScrollManager {
  constructor({ content = null } = {}) {
    if (support.mobile || content === null) {
      document.body.classList.add('is-mobile');
      return;
    }

    this.raf = null;

    this.DOM = {
      content,
      sections: content.querySelectorAll('[data-scroll-section]')
    };

    this.options = {
      firefoxMultiplier: 15,
      keyStep: 120
    };

    this.data = {
      current: 0,
      target: 0,
      ease: 0.075,
      scrollHeight: content.getBoundingClientRect().height
    };

    this.animatedSections = [];

    this.sectionOne = new SectionOne({ section: content.querySelector('.right-image') });
    this.animatedSections.push(this.sectionOne);

    this.sectionTwo = new SectionTwo({ section: content.querySelector('.description') });
    this.animatedSections.push(this.sectionTwo);

    this.sectionThree = new SectionThree({ section: content.querySelector('.sign-up') });
    this.animatedSections.push(this.sectionThree);

    this.bindFns();
    this.init();
  }

  bindFns() {
    ['run', 'wheel', 'resize', 'keyDown'].forEach(fn => (this[fn] = this[fn].bind(this)));
  }

  animateSections(current) {
    this.animatedSections.forEach(section => section && section.run(current));
  }

  wheel(e) {
    if (support.firefox && e.deltaMode == 1) {
      this.data.target += e.deltaY * this.options.firefoxMultiplier;
    } else {
      this.data.target += e.deltaY;
    }

    this.clampTarget();
  }

  keyDown(e) {
    switch (e.keyCode) {
      case keyCodes.LEFT:
        //this.data.target = this.options.keyStep;
        break;

      case keyCodes.UP:
        this.data.target -= this.options.keyStep;
        this.clampTarget();
        break;

      case keyCodes.RIGHT:
        // this.data.target = - this.options.keyStep;
        break;

      case keyCodes.DOWN:
        this.data.target += this.options.keyStep;
        this.clampTarget();
        break;

      case e.shiftKey && keyCodes.SPACE:
        this.data.target -= config.windowHeight;
        this.clampTarget();
        break;

      case keyCodes.SPACE:
        this.data.target += config.windowHeight;
        this.clampTarget();
        break;

      default:
        return;
    }
  }

  clampTarget() {
    this.data.target = math.clamp(0, this.data.scrollHeight - config.windowHeight, this.data.target);
  }

  run() {
    this.data.current = math.lerp(this.data.current, this.data.target, this.data.ease).toFixed(2);

    if (this.data.current < 0.1) {
      this.data.current = 0;
    }

    this.requestAnimationFrame();

    this.DOM.sections.forEach(section => {
      section.style.transform = `translate3d(0, ${-1 * this.data.current}px, 0)`;
    });

    this.animatedSections && this.animateSections({ scrollTop: this.data.current, target: this.data.target });
  }

  requestAnimationFrame() {
    this.raf = requestAnimationFrame(this.run);
  }

  cancelAnimationFrame() {
    cancelAnimationFrame(this.raf);
  }

  init() {
    // prep browser for transform
    this.DOM.sections.forEach(section => {
      section.style.transform = `translate3d(0, ${-1 * this.data.scrollHeight - config.windowHeight}px, 0)`;
      section.style.transform = `translate3d(0, 0, 0)`;
    });

    this.run();
    window.addEventListener('wheel', this.wheel);
    window.addEventListener('resize', this.resize);
    window.addEventListener('keydown', this.keyDown);
  }

  destroy() {
    this.cancelAnimationFrame();
    window.removeEventListener('wheel', this.wheel);
    window.removeEventListener('resize', this.resize);
    window.removeEventListener('keydown', this.keyDown);
  }

  resize() {
    this.data.scrollHeight = this.DOM.content.getBoundingClientRect().height;
    config.windowHeight = window.innerHeight;
    config.windowWidth = window.innerWidth;
  }
}

class Section {
  constructor({ section = null } = {}) {
    const bounds = section.getBoundingClientRect();

    this.data = {
      current: 0,
      progress: 0,
      height: bounds.height,
      top: bounds.top,
      bottom: bounds.bottom,
      scrollTop: 0,
      visibleOnLoad: false
    };

    this.checkViewPort();

    if (this.isVisible) {
      this.data.visibleOnLoad = true;
      this.getData(this.data.visibleOnLoad);
    }
  }

  checkViewPort() {
    this.isVisible = this.data.top < config.windowHeight + this.data.scrollTop && this.data.bottom > this.data.scrollTop;
  }

  // get data if section is out of viewport
  getData(visibleOnLoad = false) {
    if (visibleOnLoad) {
      this.data.current = this.data.scrollTop;
      this.data.progress = math.normalize(this.data.current, this.data.bottom, 0);
    } else {
      this.data.current = this.data.scrollTop + config.windowHeight - this.data.top;
      this.data.progress = math.normalize(this.data.current, config.windowHeight + this.data.height, 0);
    }
  }

  run({ scrollTop, target }) {
    this.data.scrollTop = parseInt(scrollTop);
    this.checkViewPort();
    if (!this.isVisible) return;
    this.getData(this.data.visibleOnLoad);
  }
}

class SectionOne extends Section {
  constructor({ section = null } = {}) {
    super({ section });

    this.DOM = {
      imageOverflow: section.querySelector('.right-image__overflow'),
      image: section.querySelector('.right-image__container')
    };
  }

  run({ scrollTop, target }) {
    super.run({ scrollTop, target });
    if (!this.isVisible) return;

    // animate here
    const section = {
      progress: this.data.progress,
      keyframeA: math.normalize(this.data.current, this.data.bottom * 0.5, 0),
      keyframeB: math.normalize(this.data.current, this.data.bottom * 0.5, 0) - 1
    };

    section.keyframeA = math.clamp(0, 1, section.keyframeA);
    section.keyframeB = math.clamp(0, 1, section.keyframeB);

    let keyframe;
    if (section.keyframeA < 1) {
      keyframe = `translate3d(0, ${math.denormalize(ease.inOutQuad(section.keyframeA), -260, 0)}px, 0)`;
    } else {
      keyframe = `translate3d(0, ${math.denormalize(section.keyframeB, 0, -260)}px, 0)`;
    }

    this.DOM.imageOverflow.style.transform = `translate3d(0, ${math.denormalize(ease.outQuint(this.data.progress), -260, 0)}px, 0)`;
    // this.DOM.imageOverflow.style.transform = keyframe;
    this.DOM.image.style.transform = `translate3d(0, ${math.denormalize(section.progress, 100, 0)}px, 0)`;
  }
}

class SectionTwo extends Section {
  constructor({ section = null } = {}) {
    super({ section });

    this.DOM = { container: section.querySelector('.description__container') };

    this.animate = {
      from: { y: 0 },
      to: { y: 25 }
    };
  }

  run(scrollTop) {
    super.run(scrollTop);
    if (!this.isVisible) return;

    // animate
    const yTranslate = math.denormalize(this.data.progress, this.animate.to.y, this.animate.from.y);
    this.DOM.container.style.transform = `translate3d(0, ${yTranslate}px, 0)`;
  }
}

class SectionThree extends Section {
  constructor({ section = null } = {}) {
    super({ section });

    this.DOM = {
      container: document.getElementsByClassName('sign-up__container')[0],
      fixedImageOverflow: document.getElementById('image-two-overflow'),
      fixedImage: document.getElementById('image-two')
    };
  }

  run(scrollTop) {
    super.run(scrollTop);
    if (!this.isVisible) return;

    this.data.progress = math.normalize(this.data.current, this.data.height, 0);

    // animate
    this.DOM.container.style.transform = `translate3d(0, ${math.denormalize(this.data.progress, 0, 100)}px, 0)`;
    this.DOM.fixedImageOverflow.style.transform = `translate3d(0, ${math.denormalize(ease.inOutQuad(this.data.progress), 0, 100)}px, 0)`;
    this.DOM.fixedImage.style.transform = `translate3d(0, ${math.denormalize(this.data.progress, -100, 0)}%, 0)`;
  }
}

class Introduction {
  constructor() {
    this.DOM = {
    navigation: document.getElementById('navigation'),
    links: document.getElementById('links'),
    topHeadline: document.getElementById('top-headline'),
    bottomHeadline: document.getElementById('bottom-headline'),
    fixedImageContainer: document.getElementById('fixed-image-container'),
    fixedImageOverflow: document.getElementById('image-one-overflow'),
    fixedImage: document.getElementById('fixed-image'),
    text: document.getElementById('text'),
    rightImage: document.getElementById('right-image'),
    description: document.getElementById('description')
  };

  this.animation = anime.timeline({
    easing: 'easeOutExpo'
  });

  this.animation
    .add({
        targets: this.DOM.navigation,
        translateY: ['-100%', '0%'],
        duration: 1000
      }, 0)
    .add({
        targets: this.DOM.links,
        translateY: [-60, 0],
        duration: 900,
        delay: 100
      }, 0)
    .add({
        targets: this.DOM.topHeadline,
        translateX: ['-80%', '0%'],
        duration: 900,
        delay: 100
      }, 0)
    .add({
        targets: [this.DOM.bottomHeadline, this.DOM.text],
        translateX: ['-65%', '0%'],
        duration: 1000
      }, 0)
    .add({
        targets: this.DOM.rightImage,
        translateX: ['110%', '0%'],
        translateY: [300, 0],
        duration: 750,
        delay: 250
      }, 0)
    .add({
        targets: this.DOM.description,
        translateX: ['100%', '0%'],
        translateY: [200, 0],
        duration: 800,
        delay: 200
      }, 0)
    .add({
        targets: [this.DOM.fixedImageContainer, this.DOM.fixedImageOverflow],
        translateX: ['50%', '0%'],
        translateY: [300, 0],
        duration: 1000
      }, 0)
    .add({
        targets: this.DOM.fixedImage,
        translateX: ['-100%', '0%'],
        translateY: [-500, 0],
        duration: 1000
      }, 0);

    this.animation.pause();
  }
  
  play() {
    this.animation.play();
  }
  
};


// INIT PAGE
window.addEventListener('load', () => {
  const content = document.querySelector('[data-scroll]');
  const introduction = new Introduction();

  introduction.animation.complete = () => new ScrollManager({ content });

  document.querySelector(".main-body").classList.remove('loading');
  setTimeout(() => introduction.play(), 1000);
});

            
          
!
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.

Console