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

Auto Save

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

              
                <header id="site-header">
    <div class="header-container">
        <div class="header-logo | animate-scroll-fade-in" data-delay="0.25" data-duration="1.5">
            <a href="/">
              <svg viewBox="0 0 138 26" fill="none" stroke="greenyellow" stroke-width="2.3" stroke-linecap="round" stroke-linejoin="round" title="CodePen"><path d="M15 8a7 7 0 100 10m7-8.7L33 2l11 7.3v7.4L33 24l-11-7.3zm0 0l11 7.4 11-7.4m0 7.4L33 9.3l-11 7.4M33 2v7.3m0 7.4V24M52 6h5a7 7 0 010 14h-5zm28 0h-9v14h9m-9-7h6m11 1h6a4 4 0 000-8h-6v14m26-14h-9v14h9m-9-7h6m11 7V6l11 14V6"></path></svg>
            </a>
        </div>

        <div class="header-nav | animate-scroll-fade-in" data-delay="0.5" data-duration="1.5">
            <nav class="nav-traditional" aria-label="Navigation Menu">
                <ul>
                    <li class="nav-item standard"><a href="/" class="nav-link">About</a></li>
                    <li class="nav-item standard"><a href="/" class="nav-link">Services</a></li>
                    <li class="nav-item standard"><a href="/" class="nav-link">Portfolio</a></li>
                    <li class="nav-item standard"><a href="/" class="nav-link">Blog</a></li>
                    <li class="nav-item standard"><a href="/" class="nav-link">Contact</a></li>
                </ul>
            </nav>
        </div>
    </div>
</header>

<section id="site-masthead" role="complementary" aria-label="Photo Slideshow" class="animate-scroll-fade-in" data-delay="0" data-duration="1.5">
    <div class="masthead-slideshow">
        <div class="masthead-content | animate-scroll-fade-in" data-delay="0.75" data-duration="1.5">
            <div class="masthead-content-container">
                <h1>Building Cool Things Since 1988</h1>
            </div>
        </div>

        <div class="glide">
            <img src="https://images.unsplash.com/photo-1635170870336-67546b863d13" alt="">
        </div>
    </div>
</section>

<main>
    <section class="content content-split">
        <div class="content-split-item content-split-text | animate-scroll-slide-horizontal" data-delay="0.25" data-trigger="100px" data-scroller="95%" data-position="-100">
            <h2>Site Content</h2>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Distinctio mollitia nostrum, praesentium provident officia odit possimus commodi blanditiis fugiat animi recusandae, necessitatibus assumenda cumque vel, molestias quo.</p>
          <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Distinctio mollitia nostrum, praesentium provident officia odit possimus commodi blanditiis fugiat animi recusandae, necessitatibus assumenda cumque vel, molestias quo.</p>
        </div>

        <div class="content-split-item content-split-image | animate-scroll-slide-horizontal" data-delay="0.25" data-trigger="100px" data-scroller="95%" data-position="100">
            <img src="https://images.unsplash.com/photo-1542324253097-09d465f007bc" alt="">
        </div>
    </section>
  
  <section class="content content-small | animate-children-scroll-fade-in" data-scroller="95%"  data-delay="0.25">
    <div class="content-item">
      <h2>This is a heading 1</h2>
      <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eligendi ipsam architecto natus dolor eius voluptatem similique quod corporis quaerat, quos magnam voluptatibus sequi illo rem porro expedita voluptatum. Repellat, voluptatem.</p>
    </div>
    
    <div class="content-item">
      <h2>This is a heading 2</h2>
      <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eligendi ipsam architecto natus dolor eius voluptatem similique quod corporis quaerat, quos magnam voluptatibus sequi illo rem porro expedita voluptatum. Repellat, voluptatem.</p>
    </div>
    
    <div class="content-item">
      <h2>This is a heading 3</h2>
      <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eligendi ipsam architecto natus dolor eius voluptatem similique quod corporis quaerat, quos magnam voluptatibus sequi illo rem porro expedita voluptatum. Repellat, voluptatem.</p>
    </div>
    
    <div class="content-item">
      <h2>This is a heading 4</h2>
      <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eligendi ipsam architecto natus dolor eius voluptatem similique quod corporis quaerat, quos magnam voluptatibus sequi illo rem porro expedita voluptatum. Repellat, voluptatem.</p>
    </div>
  </section>
</main>
              
            
!

CSS

              
                body {
  margin: 0;
  background-color: #000;
  color: #fff;
  font-family: 'Monterrat', sans-serif;
}

h1,
h2 {
  margin: 0 0 0.5em 0;
  line-height: 1;
}

h1 {
  font-size: 3rem;
  
  @media (max-width: 1300px) {
    font-size: 2rem;
  }
}

h2 {
  font-size: 2.5rem;
}

p {
  margin: 0 0 1em 0;
  font-size: 1.5rem;
  line-height: 1.75;
}

.text-center {
  text-align: center;
}




// **************************************************
//  Header
// **************************************************
header#site-header {
  position: sticky;
  top: 0;
  width: 100%;
  z-index: 10000;
  background-color: #323233;
}




// **************************************************
//  Header Container
// **************************************************
.header-container {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  gap: 2em;
  max-width: 1920px;
  margin-inline: auto;
  padding-block: 2.25em;
  padding-inline: 1em;

  @media (max-width: 1360px) {
    flex-direction: column;
    gap: 0;
    padding-block: 1em;
  }
}




// **************************************************
//  Header Logo
// **************************************************
.header-logo {
  flex-grow: 0;
  flex-shrink: 1;
  flex-basis: auto;
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;

  a {
    width: 420px;
    
    @media (max-width: 1360px) {
      width: 210px;
    }
  }

  img {
    display: block;
  }
}




// **************************************************
//  Header Nav
// **************************************************
.header-nav {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}

.nav-traditional {
  margin: 0;
  padding: 0;
  opacity: 1;
  display: block;

  >ul {
    display: flex;
    gap: 0.25em;
    margin: 0;
    padding: 0;
    list-style: none;
    
    @media(max-width: 540px) {
      gap: 0;
    }

    >li {
      position: relative;

      >a {
        display: block;
        padding-block: 0.6em;
        padding-inline: 1.2em;
        color: #fff;
        font-size: 1.4rem;
        font-family: 'Montserrat', sans-serif;
        line-height: 1;
        font-weight: 400;
        text-decoration: none;
        
        @media (max-width: 1360px) {
          font-size: 1rem;
        }
        
        @media(max-width: 540px) {
          padding-inline: 0.75em
        }
      }

      &.standard {
        >a {
          transition: all 0.5s;

          &:hover,
          &:focus{
            background-color: #5A5F73;
            color: #fff;
          }
        }
      }
    }
  }
}




// **************************************************
//  Masthead Slideshow
// **************************************************
#site-masthead {
  position: relative;
  background-color: #000;
}

.masthead-slideshow {
  .glide {
    max-height: 960px;
  }

  img {
    display: block;
    object-fit: cover;
    width: 100%;
    height: 100%;
    max-width: none;
  }
}

.masthead-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding-inline: 1em;
  z-index: 101;
  color: #fff;
  
  h1 {
    margin: 0 0 0.25em 0;
    text-align: center;
  }
} 




// **************************************************
//  Main
// **************************************************
main {
  padding-block: 5em;
  padding-inline: 1em;
}




// **************************************************
//  Content
// **************************************************
.content {
  max-width: 1920px;
  margin-inline: auto;
  padding-block: 2.25em;
  padding-inline: 1em;
  
  &.content-small {
    max-width: 1300px;
  }
}

.content-item {
  margin-bottom: 5em;
}

.content-split {
  display: flex;
}

.content-split-item {
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: 50%;
}

.content-split-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.content-split-image {
  min-width: 0;

  img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 600px;
    object-fit: cover;
  }
}




              
            
!

JS

              
                // Created by Alex Winter
// Created: 2022-07-25
// Modified: 2022-11-28




// **************************************************
// Masthead Slideshow Height
// **************************************************
const header = document.querySelector('#site-header');
const masthead = document.querySelector('.masthead-slideshow .glide');

// ternary operator
// if the element is null (undefined and doesnt exist in DOM) then set its offsetHeight value to 0
const headerHeight = header != null ? header.offsetHeight : 0; // get header height

// define viewport height
let viewportHeight = window.innerHeight;

const setMastheadHeight = () => {
    // calculate masthead height
    let mastheadHeight = viewportHeight - headerHeight;

    // apply masthead height value to masthead element
    if (masthead) {
        masthead.style.height = mastheadHeight  + 'px';
    };
};
setMastheadHeight();




// **************************************************
//  GSAP Animations
// **************************************************
// Register the ScrollTrigger plug-in
gsap.registerPlugin(ScrollTrigger)




// **************************************************
//  GSAP - Scroll - Refresh All ScrollTriggers 
// **************************************************
// * Call this function within your scrollTrigger timeline to recalculate the positioning of all of the ScrollTriggers on the page.
// * This is useful on for the "Site Header" for example because it is a fixed element that changes height after scrolling down below the fold, which breaks the placement of all other ScrollTriggers on the page.
// * This will fire after X miliseconds, hopefully after the animations have finished. Change the amount of time as needed.
const refreshScrollTrigger = () => {
    setTimeout(() => {
        ScrollTrigger.refresh() // https://greensock.com/docs/v3/Plugins/ScrollTrigger/static.refresh()
        // console.log('setTimeout has elapsed')
    }, 2000)
    // console.log('toggled inactive or active')
}




// **************************************************
//  GSAP - Scroll - Fade In (Selected element's children)
// **************************************************
// Class:       animate-children-scroll-fade-in
// Description: This appends the 'animate-fade-in-scroll' class and its data attributes to all respective child elements
// data-delay    = number (float)      - default is 0
// data-duration = number (float)      - default is 1
// data-trigger  = top, center, bottom - default is top
// data-scroller = top, center, bottom - default is bottom
// data-markers  = false, true         - default is false
let animateChildrenScrollFadeIn = document.querySelectorAll('.animate-children-scroll-fade-in')
animateChildrenScrollFadeIn.forEach((element) => {
    element.querySelectorAll(':scope > *').forEach((childElement) => {
        childElement.classList.add('animate-scroll-fade-in')

        if (element.dataset.delay) {
            childElement.dataset.delay = parseFloat(element.dataset.delay)
        }

        if (element.dataset.duration) {
            childElement.dataset.duration = parseFloat(element.dataset.duration)
        }

        if (element.dataset.trigger) {
            childElement.dataset.trigger = element.dataset.trigger
        }

        if (element.dataset.scroller) {
            childElement.dataset.scroller = element.dataset.scroller
        }

        if (element.dataset.markers) {
            childElement.dataset.markers = element.dataset.markers
        }
    })
})



// **************************************************
//  GSAP - Scroll - Fade In (Selected element only)
// **************************************************
// Class:       animate-scroll-fade-in
// Description: Fade in from opacity 0
// data-delay    = number (float)      - default is 0
// data-duration = number (float)      - default is 1
// data-trigger  = top, center, bottom - default is top
// data-scroller = top, center, bottom - default is bottom
// data-markers  = false, true         - default is false
let animateScrollFadeIn = gsap.utils.toArray('.animate-scroll-fade-in')
animateScrollFadeIn.forEach((element) => {
    let dataDelay = 0;
    if (element.dataset.delay) {
        dataDelay = parseFloat(element.dataset.delay)
    }

    let dataDuration = 1;
    if (element.dataset.duration) {
        dataDuration = parseFloat(element.dataset.duration)
    }

    let dataTrigger = 'top'
    if (element.dataset.trigger) {
        dataTrigger = element.dataset.trigger
    }

    let dataScroller = 'bottom'
    if (element.dataset.scroller) {
        dataScroller = element.dataset.scroller
    }

    let dataMarkers = false
    if (element.dataset.markers) {
        dataMarkers = element.dataset.markers
    }

    let timeline = gsap.timeline({
        scrollTrigger: {
            trigger: element,
            start: dataTrigger + " " + dataScroller,
            markers: dataMarkers,
            toggleActions: "play none none none",
            toggleClass: "scrolled"
        }
    })

    timeline.from(element, {
        opacity: 0,
        delay: dataDelay,
        duration: dataDuration
    })
})




// **************************************************
//  GSAP - Scroll - Slide Horizontal
// **************************************************
// Class:       animate-scroll-slide-horizontal
// Description: Slide in from left or right
// data-delay    = number (float)      - default is 0
// data-duration = number (float)      - default is 1
// data-trigger  = top, center, bottom - default is top
// data-scroller = top, center, bottom - default is bottom
// data-markers  = false, true         - default is false
// data-position = px, em, %, vh, etc  - default is "100px"
let animateScrollSlideHorizontal = gsap.utils.toArray('.animate-scroll-slide-horizontal')
animateScrollSlideHorizontal.forEach((element) => {
    let dataDelay = 0;
    if (element.dataset.delay) {
        dataDelay = parseFloat(element.dataset.delay)
    }

    let dataDuration = 1;
    if (element.dataset.duration) {
        dataDuration = parseFloat(element.dataset.duration)
    }

    let dataTrigger = 'top'
    if (element.dataset.trigger) {
        dataTrigger = element.dataset.trigger
    }

    let dataScroller = 'bottom'
    if (element.dataset.scroller) {
        dataScroller = element.dataset.scroller
    }

    let dataMarkers = false
    if (element.dataset.markers) {
        dataMarkers = element.dataset.markers
    }

    let dataPosition = "100px";
    if (element.dataset.position) {
        dataPosition = element.dataset.position
    }

    let timeline = gsap.timeline({
        scrollTrigger: {
            trigger: element,
            start: dataTrigger + " " + dataScroller,
            markers: dataMarkers,
            toggleActions: "play none none none",
            toggleClass: "scrolled"
        }
    })

    timeline.from(element, {
        x: dataPosition,
        opacity: 0,
        delay: dataDelay,
        duration: dataDuration
    })
})




// **************************************************
//  GSAP - Scroll - Slide Vertical
// **************************************************
// Class:       animate-scroll-slide-vertical
// Description: Slide in from top or bottom
// data-delay    = number (float)      - default is 0
// data-duration = number (float)      - default is 1
// data-trigger  = top, center, bottom - default is top
// data-scroller = top, center, bottom - default is bottom
// data-markers  = false, true         - default is false
// data-position = px, em, %, vh, etc  - default is "100px"
let animateScrollSlideVertical = gsap.utils.toArray('.animate-scroll-slide-vertical')
animateScrollSlideVertical.forEach((element) => {
    let dataDelay = 0;
    if (element.dataset.delay) {
        dataDelay = parseFloat(element.dataset.delay)
    }

    let dataDuration = 1;
    if (element.dataset.duration) {
        dataDuration = parseFloat(element.dataset.duration)
    }

    let dataTrigger = 'top'
    if (element.dataset.trigger) {
        dataTrigger = element.dataset.trigger
    }

    let dataScroller = 'bottom'
    if (element.dataset.scroller) {
        dataScroller = element.dataset.scroller
    }

    let dataMarkers = false
    if (element.dataset.markers) {
        dataMarkers = element.dataset.markers
    }

    let dataPosition = "100px";
    if (element.dataset.position) {
        dataPosition = element.dataset.position
    }

    let timeline = gsap.timeline({
        scrollTrigger: {
            trigger: element,
            start: dataTrigger + " " + dataScroller,
            markers: dataMarkers,
            toggleActions: "play none none none"
        }
    })

    timeline.from(element, {
        y: dataPosition,
        opacity: 0,
        delay: dataDelay,
        duration: dataDuration
    })
})




// **************************************************
//  GSAP - Scroll - Site Header
// **************************************************
const headerContainer = document.querySelector('#site-header .header-container')
const headerLogo = document.querySelector('.header-logo a')
ScrollTrigger.matchMedia({
    "(min-width: 540px) and (max-height: 1100px)": function() {
        const timeline = gsap.timeline({
            scrollTrigger: {
                trigger: 'main',
                start: "top 90%",
                toggleActions: "play none none reverse",
                onToggle: self => refreshScrollTrigger(),
                // markers: true,
            }
        });
        timeline.to(headerContainer, { paddingBlock: '20px' })
        .to(headerLogo, { width: '320px' }, '<')
    }
})
              
            
!
999px

Console