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

              
                <section class="header">
  <div class="headercontainer">
    <h1>Animation on Scroll Showcase</h1>
    <div class="headertxt">
      #CodePenChallenge Scrolling Animations<br>
      It's the final week of the June #CodePenChallenge!
    </div>
  </div>
</section>
<section class="content1">
  <div id="texthighlighting" class="texthighlightbox">
    <span>Lorem</span><span>ipsum</span><span>dolor</span><span>sit</span><span>amet,</span><span>consetetur</span><span>sadipscing</span><span>elitr,</span><span>sed</span><span>diam</span><span>nonumy</span><span>eirmod</span><span>tempor</span><span>invidunt</span><span>ut</span><span>labore</span><span>et</span><span>dolore</span><span>magna</span><span>aliquyam</span><span>erat,</span><span>sed</span><span>diam</span><span>voluptua.</span><span>At</span><span>vero</span><span>eos</span><span>et</span><span>accusam</span><span>et</span><span>justo</span><span>duo</span><span>dolores</span><span>et</span><span>ea</span><span>rebum.</span><span>Stet</span><span>clita</span><span>kasd</span><span>gubergren,</span><span>no</span><span>sea</span><span>takimata</span><span>sanctus</span><span>est</span><span>Lorem</span><span>ipsum</span><span>dolor</span><span>sit</span><span>amet.</span>
  </div>
</section>
<section class="content2">
  <div class="flyintxtbox" id="flyintxt">
    <span>We</span><span>are</span><span>creative</span><span>minds,</span><span>designers,</span><span>programmers,</span><span>and</span><span>much</span><span>more.</span><span>Our</span><span>passion</span><span>drives</span><span>us</span><span>to</span><span>create</span><span>innovative</span><span>solutions</span><span>and</span><span>bring</span><span>unique</span><span>projects</span><span>to</span><span>life.</span>
  </div>
</section>
<section class="sticky-txt">
  <div class="content-left" id="left-content">
    <h2>CodePen is a site where</h2>
  </div>
  <div class="content-right">
    <div class="content-box-div-right">
      <h2>Creativity Flourishes</h2>
      <p>Developers and designers come together to experiment with code and create stunning visual effects.</p>
    </div>
    <div class="content-box-div-right">
      <h2>Learning Happens</h2>
      <p>People of all skill levels share knowledge, inspire each other, and grow their programming skills.</p>
    </div>
    <div class="content-box-div-right">
      <h2>Innovation Thrives</h2>
      <p>New ides are born, and cutting-edge web technologies are showcased and explored.</p>
    </div>
  </div>
</section>
<section class="content7">
  <svg class="svgScrollAnimation" width="300" height="350" xmlns="http://www.w3.org/2000/svg">
    <circle id="circle1" cx="50" cy="50" r="10" fill="#333" />
    <text id="text1" x="70" y="55" fill="#333">Responsive Design</text>

    <circle id="circle2" cx="50" cy="175" r="10" fill="#333" />
    <text id="text2" x="70" y="180" fill="#333">User Experience</text>

    <circle id="circle3" cx="50" cy="300" r="10" fill="#333" />
    <text id="text3" x="70" y="305" fill="#333">Visual Impact</text>

    <line id="lineDeactivated" x1="50" y1="50" x2="50" y2="300" stroke="#333" stroke-width="2" />

    <line id="lineActivated" x1="50" y1="50" x2="50" y2="50" stroke="#fff" stroke-width="2" />
  </svg>
</section>
<section class="content4">
  <div class="containerflexbox">
    <div id="flexbox1" class="flexbox">
      <h3>What are Scroll Animations?</h3>
      <p>Scroll animations are visual effects triggered as users scroll down a webpage. They enhance user experience by providing engaging and interactive elements.</p>
    </div>
    <div id="flexbox2" class="flexbox">
      <h3>How to Implement?</h3>
      <p>Use CSS properties like <code>@keyframes</code> and <code>animation</code> in combination with JavaScript libraries such as ScrollMagic or Intersection Observer API to trigger animations.</p>
    </div>
    <div id="flexbox3" class="flexbox">
      <h3>Examples & Tips</h3>
      <p>Create smooth transitions with <code>transform</code> and <code>opacity</code>. Keep animations subtle to avoid distracting users. Test across different devices for performance.</p>
    </div>
  </div>
</section>
<section class="content5">
  <div class="split-image-container" id="splitImageContainer">
    <div id="divtop">
      <div class="image1-top"><img src="https://rassweiler-it.de/images/codepen-without-css.png"></div>
      <div class="image2-top"><img src="https://rassweiler-it.de/images/codepen-with-css.png"></div>
    </div>
    <div id="divbottom">
      <div class="image2-bottom"><img src="https://rassweiler-it.de/images/codepen-with-css.png"></div>
      <div class="image1-bottom"><img src="https://rassweiler-it.de/images/codepen-without-css.png"></div>
    </div>
  </div>
</section>
<section class="content6">
  <div class="container" id="scrollContainer">
    <div class="clip-path">#CODEPEN</div>
    <div class="background-1"></div>
    <div class="background-2"></div>
  </div>
</section>

              
            
!

CSS

              
                body {
  background: black;
  font-family: Arial, sans-serif;
  margin: 0;
  overflow-x: hidden;
}

.header {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  background: linear-gradient(0deg, rgba(0,0,0,1) 20%, rgba(255,255,255,0) 100%), repeating-linear-gradient(transparent, transparent 50px, #333 52px), repeating-linear-gradient(90deg, transparent, transparent 50px, #333 52px);
  background-attachment: fixed;
}

.header h1 {
  color: #fff;
  text-align: center;
  letter-spacing: -.03em;
  text-transform: uppercase;
  margin-top: 0;
  margin-bottom: 10px;
  font-size: 46px;
  line-height: 60px;
}

.headertxt {
  max-width: 750px;
  color: #fff;
  text-align: center;
  margin: 20px auto 40px;
  font-size: 22px;
  line-height: 36px;
}

.content1 {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.texthighlightbox {
  white-space: normal;
  word-wrap: break-word;
  width: 600px;
  max-width: 100%;
  padding: 10px;
  box-sizing: border-box;
  margin: 0 auto;
}

.texthighlightbox span {
  margin: 0 3px;
  color: #333;
  text-transform: uppercase;
  display: inline-block;
  font-size: 34px;
  line-height: 50px;
  margin: 0 3px;
}

.content2 {
  color: #fff;
  white-space: normal;
  word-wrap: break-word;
  max-width: 100%;
  padding: 10px;
  box-sizing: border-box;
  margin: 200px auto;
  text-align: center;
}

.flyintxtbox span {
  transform-origin: 0 0;
  font-weight: 300;
  line-height: 1.2;
  font-size: 100px;
  display: inline-block;
  text-transform: uppercase;
  margin: 0 15px;
  transform: translateX(-20px) scale(0.75);
  transition: 0.5s;
}

.flyintxtbox span.v2 {
  font-weight: 500;
  transform: translateX(0) scale(1);
  transition: 0.5s;
}

@media only screen and (max-width: 900px) {
  .flyintxtbox span {
    font-size: 50px;
  }
}

@media only screen and (max-width: 500px) {
  .flyintxtbox span {
    font-size: 30px;
  }
}

.sticky-txt {
  display: flex;
  align-items: flex-start;
  color: #fff;
}

.content-right {
  flex: 1;
  padding: 100px;
  box-sizing: border-box;
}
.content-left {
  flex: 1;
  position: sticky;
  will-change: transform;
  text-align: center;
  box-sizing: border-box;
  margin-top: 100px;
  margin-bottom: 100px;
}

.content-box-div-right {
  border: 1px solid rgba(210, 210, 210, .2);
  border-radius: 20px;
  margin-bottom: 30px;
  padding: 40px 20px;
  transition: transform 0.3s ease;
  box-sizing: border-box;
}

@media (max-width: 768px) {
  .sticky-txt {
    flex-direction: column;
    align-items: center;
  }
  .content-left, .content-right {
    padding: 20px;
    width: 100%;
  }
  .content-left {
    position: static;
    margin-top: 20px;
    margin-bottom: 20px;
  }
}

.content4 {
  height: auto;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
}

.containerflexbox {
  width: 100%;
  height: 300px;
  position: relative;
  margin: 100px auto;
}

.containerflexbox div {
  position: absolute;
  height: 300px;
  width: 350px;
  border: 1px solid #333;
  border-radius: 15px;
  padding: 20px;
  box-sizing: border-box;
  transition: transform 0.5s;
}

#flexbox1 {left: 50px; color: #fff; transform: translateX(0) scale(0);}
#flexbox2 {left: 50%; transform: translateX(-50%) scale(0); color: #fff;}
#flexbox3 {right: 50px; color: #fff; transform: translateX(0) scale(0);}

#flexbox1.visible {transform: translateX(0) scale(1);}
#flexbox2.visible {transform: translateX(-50%) scale(1);}
#flexbox3.visible {transform: translateX(0) scale(1);}

@media (max-width: 1200px) {
  .containerflexbox div {
    width: 300px;
  }
}

@media (max-width: 1050px) {
  .containerflexbox div {
    width: 280px;
  }
}

@media (max-width: 980px) {
  .containerflexbox {
    position: static;
    height: auto;
  }
  
  .containerflexbox div {
    width: 500px;
    position: static;
    max-width: 85%;
  }

  #flexbox1 {margin: 10px auto; color: #fff; transform: translateX(0) scale(0);}
  #flexbox2 {margin: 10px auto; color: #fff; transform: translateX(0) scale(0);}
  #flexbox3 {margin: 10px auto; color: #fff; transform: translateX(0) scale(0);}
  #flexbox1.visible, #flexbox2.visible, #flexbox3.visible {transform: translateX(0) scale(1);}
}

.content5 {
  width: 100vw;
  height: 200vh;
  overflow: hidden;
  position: relative;
}

.split-image-container {
  overflow: hidden;
  width: 100vw;
  height: 100vh;
}

#divtop, #divbottom {
  width: 200vw;
  height: 50vh;
  display: flex;
}

#divtop {
  transform: translateX(0);
}

#divbottom {
  transform: translateX(-100vw);
}

.image1-top, .image2-top, .image1-bottom, .image2-bottom {
  overflow: hidden;
  width: 100vw;
  position: relative;
}

.image1-top img, .image2-top img, .image1-bottom img, .image2-bottom img {
  height: 100vh;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.image1-top img {top: 0;}
.image2-top img {top: 0;}
.image1-bottom img {bottom: 0;}
.image2-bottom img {bottom: 0;}

.content6 {
  min-height: 100vh;
  font-family: 'Impact', sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
}

.container {
  background-color: black;
  position: relative;
  height: 65px;
  width: 250px;
  margin: 0;
  margin-left: auto;
  margin-right: auto;
  overflow: hidden;
  transition: 0.3s;
  cursor: pointer;
}

.clip-path {
  position: absolute;
  top: 0;
  color: rgb(255, 255, 255, 1);
  font-size: 60px;
  height: 65px;
  line-height: 65px;
  width: 250px;
  background-color: black;
  z-index: 2;
  mix-blend-mode: multiply;
}

.background-1 {
  position: absolute;
  top: 0;
  left: 0;
  width: 250px;
  height: 65px;
  background-color: yellow;
  z-index: 1;
  transition: left 0.3s;
}

.background-2 {
  position: absolute;
  top: 0;
  left: -250px;
  width: 250px;
  height: 65px;
  background-color: aqua;
  z-index: 1;
  transition: left 0.3s;
}

/* Custom Scrollbar for Touch devices */
::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  box-shadow: none; 
  border-radius: 2.5px;
}
 
::-webkit-scrollbar-thumb {
  background: #00FFFF;
  border-radius: 0;
  cursor: pointer;
}

::-webkit-scrollbar-thumb:hover {
  background: #7CFFFF;
}

/* Custom Scrollbar for non-touch devices */
@media (hover: hover) and (pointer: fine) {
  /* Custom Scrollbar */
  ::-webkit-scrollbar {
    width: 20px;
  }

  ::-webkit-scrollbar-track {
    box-shadow: inset 0 0 5px grey; 
    border-radius: 10px;
  }
   
  ::-webkit-scrollbar-thumb {
    background: #00FFFF; 
    border-radius: 10px;
  }

  ::-webkit-scrollbar-thumb:hover {
    background: #7CFFFF;
  }
}

.content7 {
  padding: 50px 0;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.svgScrollAnimation {
  position: relative;
  z-index: 1;
  width: 300px;
}
              
            
!

JS

              
                function adjustStickyPosition() {
  var contentLeft = document.getElementById('left-content');
  var height = contentLeft.clientHeight;
  var topOffset = 'calc(50% - ' + (height / 2) + 'px)';
  contentLeft.style.top = topOffset;
}

window.addEventListener('scroll', function() {
  const spans = document.querySelectorAll('.texthighlightbox span');
  const windowHeight = window.innerHeight;
  const content2Spans = document.querySelectorAll('.content2 .flyintxtbox span');

  let lines = [];
  let currentLine = -1;
  let lastTop = -1;

  spans.forEach((span, index) => {
    const spanRect = span.getBoundingClientRect();
    if (spanRect.top !== lastTop) {
      currentLine++;
      lines[currentLine] = [];
      lastTop = spanRect.top;
    }
    lines[currentLine].push(span);
  });

  lines.forEach(line => {
    const firstSpan = line[0];
    const firstSpanRect = firstSpan.getBoundingClientRect();
    const firstSpanCenterY = firstSpanRect.top + (firstSpanRect.height / 2);

    line.forEach((span, index) => {
      if (firstSpanCenterY <= windowHeight / 2) {
        span.style.color = '#fff';
      } else {
        span.style.color = '#333';
      }
    });
  });

  content2Spans.forEach((span) => {
    const spanRect = span.getBoundingClientRect();
    const spanBottomY =  spanRect.bottom;

    if (spanBottomY <= windowHeight) {
      span.classList.add('v2');
    } else {
      span.classList.remove('v2');
    }
  });
});

document.addEventListener('scroll', function() {
  const container = document.getElementById('scrollContainer');
  const background1 = document.querySelector('.background-1');
  const background2 = document.querySelector('.background-2');
  const rect = container.getBoundingClientRect();
  const windowHeight = window.innerHeight;
  const middleOfViewport = windowHeight / 2;

  if (rect.top < windowHeight && rect.bottom > 0) {
    const distanceToMiddle = Math.abs(rect.top + rect.height / 2 - middleOfViewport);
    const percentageScrolled = Math.min(1, distanceToMiddle / middleOfViewport);
    if (rect.top + rect.height / 2 < middleOfViewport) {
      background1.style.left = '250px';
      background2.style.left = '0px';
    } else {
      const leftValue = 250 * (1 - percentageScrolled);
      background1.style.left = `${leftValue}px`;
      background2.style.left = `${leftValue - 250}px`;
    }
  } else {
    background1.style.left = '0px';
    background2.style.left = '-250px';
  }
});

document.addEventListener('DOMContentLoaded', function () {
  const splitImageContainer = document.getElementById('splitImageContainer');
  const content5 = document.querySelector('.content5');
  const divTop = document.getElementById('divtop');
  const divBottom = document.getElementById('divbottom');

  function onScroll() {
    const containerRect = splitImageContainer.getBoundingClientRect();
    const content4Rect = content5.getBoundingClientRect();
    const viewportHeight = window.innerHeight;

    // Calculate scroll progress
    const scrollProgress = Math.min(Math.max((window.scrollY - content5.offsetTop) / (content5.offsetHeight - viewportHeight), 0), 1);

    // Update divTop and divBottom positions based on scroll progress
    const translateTopX = -scrollProgress * 100;
    const translateBottomX = -100 + (scrollProgress * 100);

    divTop.style.transform = `translateX(${translateTopX}vw)`;
    divBottom.style.transform = `translateX(${translateBottomX}vw)`;

    if (content4Rect.top <= 0 && content4Rect.bottom >= viewportHeight) {
      splitImageContainer.style.position = 'fixed';
      splitImageContainer.style.top = '0';
    } else if (content4Rect.bottom < viewportHeight) {
      splitImageContainer.style.position = 'absolute';
      splitImageContainer.style.top = (content5.offsetHeight - splitImageContainer.offsetHeight) + 'px';
    } else if (content4Rect.top > 0) {
      splitImageContainer.style.position = 'relative';
      splitImageContainer.style.top = '0';
    }
  }

  window.addEventListener('scroll', onScroll);
  // Initial call to set the correct position
  onScroll();

  const options = {
    root: null,
    rootMargin: '0px',
    threshold: 0.1
  };

  const observer = new IntersectionObserver((entries, observer) => {
    entries.forEach(entry => {
      if (entry.isIntersecting) {
        entry.target.classList.add('visible');
      } else {
        entry.target.classList.remove('visible');
      }
    });
  }, options);

  document.querySelectorAll('.flexbox').forEach(flexbox => {
    observer.observe(flexbox);
  });

});


function initialize () {
  adjustStickyPosition ();
}

window.onload = initialize;
window.onresize = initialize;

document.addEventListener('scroll', function() {
  const screenHeight = window.innerHeight;
  const circles = document.querySelectorAll('circle');
  const texts = document.querySelectorAll('text');
  const lineActivated = document.getElementById('lineActivated');

  circles.forEach((circle, index) => {
    const circleTop = circle.getBoundingClientRect().top;
    const text = texts[index];
    if (circleTop <= screenHeight / 2) {
      circle.setAttribute('fill', '#fff');
      text.setAttribute('fill', '#fff');
    } else {
      circle.setAttribute('fill', '#333');
      text.setAttribute('fill', '#333');
    }
  });

  const circle1Top = document.getElementById('circle1').getBoundingClientRect().top;
  if (circle1Top < screenHeight / 2) {
    const position = 50 + (175 - 50) * ((screenHeight / 2 - circle1Top) / (175 - 50));
    lineActivated.setAttribute('y2', Math.min(300, Math.max(50, position)));
  } else {
    lineActivated.setAttribute('y2', 50);
  }
});

              
            
!
999px

Console