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 class="header header--inverted"> Header </header>
<header class="header header--normal"> Header </header>

<div class="page">  
  <section class="section">A</section>
  <section class="section section--dark">
    B
  </section>
  <section class="section">
    C
    <button onclick="makeLarger()">Make red box higher</button>
    <div class="red">RED BOX</div>
  </section>
  <section class="section section--dark">
    D
  </section>
</div>


              
            
!

CSS

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

body {
  padding: 0;
  margin: 0;
  height: 1000px;
}

.page {
  position: relative;
  padding-top: 56px;
}

.header {
  position: fixed;
  font-size: 16px;
  padding: 20px;
  background: white;
  color: black;
  width: 100%;
  z-index: 1000;
} 

.header--inverted {
  background: black;
  color: white;
}

.section {
  min-height: 300px;
  padding: 30px;
}

.section--dark {
  background: black;
  color: white;
}

.red {
  background: red;
  width: 200px;
  height: 100px;
  color: white;
}
              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);
gsap.config({ trialWarn: false });
console.clear();

const normalNavbar = document.querySelector(".header--normal");
const invertedNavbar = document.querySelector(".header--inverted");
const darkSections = document.querySelectorAll(".section--dark");

const setEffect = () => {
  const timeline = gsap.timeline();

  timeline.set(normalNavbar, {clipPath: 'inset(0px 0 0px 0)'});
  timeline.set(invertedNavbar, {clipPath: `inset(${ invertedNavbar.offsetHeight }px 0 0px 0)`});

  darkSections.forEach((section, index) => {
      //inverted navbar
      timeline.fromTo(invertedNavbar, {
          clipPath: 'inset(0px 0 0px 0)',
          immediateRender: false
      }, {
          scrollTrigger: {
              trigger: section,
              start: () => `bottom ${ invertedNavbar.offsetHeight }px`,
              id: `navbar-from-dark${ index }`,
              end: () => `+=${ invertedNavbar.offsetHeight }px`,
              scrub: true,
              invalidateOnRefresh: true,
              // for debugging purposes set to true
              markers: true
          },
          clipPath: `inset(0px 0 ${ invertedNavbar.offsetHeight }px 0)`,
          ease: 'none'
      });

      timeline.fromTo(invertedNavbar, {
          clipPath: `inset(${ invertedNavbar.offsetHeight }px 0 0px 0)`,
          immediateRender: false
      }, {
          scrollTrigger: {
              trigger: section,
              start: () => `top ${ invertedNavbar.offsetHeight }px`,
              end: () => `+=${ Math.ceil(invertedNavbar.offsetHeight)}px`,
              id: `navbar-from-white${ index }`,
              scrub: true,
              invalidateOnRefresh: true,
              // for debugging purposes set to true
              markers: true
          },
          clipPath: 'inset(0px 0 0px 0)',
          ease: 'none'
      });

      // normal navbar
      timeline.fromTo(normalNavbar, {
          clipPath: `inset(${ normalNavbar.offsetHeight }px 0 0px 0)`,
          immediateRender: false
      }, {
          scrollTrigger: {
              trigger: section,
              start: () => `bottom ${ normalNavbar.offsetHeight }px`,
              id: `navbar-normal-from-dark${ index }`,
              end: () => `+=${ normalNavbar.offsetHeight }px`,
              scrub: true,
              invalidateOnRefresh: true,
              // for debugging purposes set to true
              markers: true
          },
          clipPath: 'inset(0px 0 0px 0)',
          ease: 'none'
      });

      timeline.fromTo(normalNavbar, {
          immediateRender: false,
          clipPath: 'inset(0px 0 0px 0)',
      }, {
          scrollTrigger: {
              trigger: section,
              start: () => `top ${ normalNavbar.offsetHeight }px`,
              end: () => `+=${ Math.ceil(normalNavbar.offsetHeight)}px`,
              id: `navbar-normal-from-white${ index }`,
              scrub: true,
              invalidateOnRefresh: true,
              // for debugging purposes set to true
              markers: true
          },
          clipPath: `inset(0px 0 ${ normalNavbar.offsetHeight }px 0)`,
          ease: 'none'
      });
  });
}

const makeLarger = () => {
  const redBox = document.querySelector(".red");
  redBox.style.height = "800px";
}

const killScrollTriggers = () => {
			const allTriggers = ScrollTrigger.getAll();
			allTriggers.forEach((trigger) => {
				if (trigger.trigger.classList.contains('section--dark')) {
					trigger.kill(true);
				}
			});
  
      console.log(ScrollTrigger.getAll(), "killed?");
}

const setDocumentHeightObserver = () => {
			const body = document.querySelector('body');

			const observer = new ResizeObserver(() => {
        console.log("height changed");
        ScrollTrigger.refresh()
        //killScrollTriggers();
				//setEffect();
			});

			for (let i = 0; i < body.children.length; i++) {
				observer.observe(body.children[i]);
			}
}

setEffect();
setDocumentHeightObserver();
              
            
!
999px

Console