Patti Supply
/
Scroll Highlight Text

Scroll Highlight Text

Preview

Installation

Copy the element to Webflow

Copy to Webflow
Copied to clipboard!
{"type":"@webflow/XscpData","payload":{"nodes":[{"_id":"33545a55-4df9-6e48-5d61-7885b5f7c5cb","type":"Block","tag":"div","classes":["1e34f292-9caa-28c2-cd62-570eb6d6fd85"],"children":["91319699-a26d-0340-c25e-ea69cfe25d2b","ff028094-79e8-392e-c35d-cb719b6eba7e"],"data":{"tag":"div","text":false,"devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[],"search":{"exclude":false},"visibility":{"conditions":[],"keepInHtml":{"tag":"False","val":{}}}}},{"_id":"91319699-a26d-0340-c25e-ea69cfe25d2b","type":"HtmlEmbed","meta":{"displayName":"p002-css"},"tag":"div","classes":[],"children":[],"v":"","data":{"search":{"exclude":true},"embed":{"type":"html","meta":{"html":"","div":false,"script":false,"compilable":false,"iframe":false}},"insideRTE":false,"content":"<style>\n .p002-scroll-highlight_mark {\n background-image: linear-gradient(rgba(70, 110, 255, 0.28), rgba(70, 110, 255, 0.28));\n background-repeat: no-repeat;\n background-position: left bottom;\n background-size: 0% 100%;\n transition: background-size 0.8s cubic-bezier(0.22, 1, 0.36, 1);\n }\n\n .p002-scroll-highlight.is-visible .p002-scroll-highlight_mark {\n background-size: 100% 100%;\n transition-delay: var(--p002-delay, 200ms);\n }\n\n @media (prefers-reduced-motion: reduce) {\n .p002-scroll-highlight .p002-scroll-highlight_mark,\n .p002-scroll-highlight.is-visible .p002-scroll-highlight_mark {\n background-size: 100% 100%;\n transition: none;\n }\n }\n</style>","devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[],"visibility":{"conditions":[],"keepInHtml":{"tag":"False","val":{}}}}},{"_id":"ff028094-79e8-392e-c35d-cb719b6eba7e","type":"Paragraph","tag":"p","classes":["3249fbe9-0116-af9c-8e66-8061060b735e"],"children":["9e1448fb-4c02-4a2a-90c6-30ebbeac77d3","5241500c-f96e-33f4-2697-3aea83946b60","30d3a3a5-5cc5-1f30-c4f5-dd25f100a5c1","90395c13-21cd-dc35-3d5a-07a4bc16bf4f","ad85d412-39ee-4e38-bfdc-2c46dc9216db"],"data":{"devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[],"search":{"exclude":false},"visibility":{"conditions":[],"keepInHtml":{"tag":"False","val":{}}}}},{"_id":"9e1448fb-4c02-4a2a-90c6-30ebbeac77d3","text":true,"v":"We build websites that feel "},{"_id":"5241500c-f96e-33f4-2697-3aea83946b60","type":"Span","tag":"span","classes":["987ff809-e736-c33d-6163-789bfdb0b039"],"children":["9aea831d-b325-09b5-f5ca-7ad759bc9c66"],"data":{"devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[],"search":{"exclude":false},"visibility":{"conditions":[],"keepInHtml":{"tag":"False","val":{}}}}},{"_id":"9aea831d-b325-09b5-f5ca-7ad759bc9c66","text":true,"v":"alive"},{"_id":"30d3a3a5-5cc5-1f30-c4f5-dd25f100a5c1","text":true,"v":" and turn simple layouts into "},{"_id":"90395c13-21cd-dc35-3d5a-07a4bc16bf4f","type":"Span","tag":"span","classes":["987ff809-e736-c33d-6163-789bfdb0b039"],"children":["426b3352-601a-dca2-cad2-c4d9ba2bca62"],"data":{"devlink":{"runtimeProps":{},"slot":""},"displayName":"","attr":{"id":""},"xattr":[],"search":{"exclude":false},"visibility":{"conditions":[],"keepInHtml":{"tag":"False","val":{}}}}},{"_id":"426b3352-601a-dca2-cad2-c4d9ba2bca62","text":true,"v":"memorable"},{"_id":"ad85d412-39ee-4e38-bfdc-2c46dc9216db","text":true,"v":" experiences."}],"styles":[{"_id":"1e34f292-9caa-28c2-cd62-570eb6d6fd85","fake":false,"type":"class","name":"p002-scroll-highlight","namespace":"","comb":"","styleLess":"display: flex; height: 70vh; max-width: 42rem; justify-content: center; align-items: center; text-align: center;","variants":{},"children":[],"createdBy":"6a524a3cbc0fac0d25bf4b97","origin":null,"selector":null},{"_id":"3249fbe9-0116-af9c-8e66-8061060b735e","fake":false,"type":"class","name":"p002-scroll-highlight_text","namespace":"","comb":"","styleLess":"font-family: Verdana; font-size: 3rem; line-height: 3.5rem; font-weight: 400;","variants":{"small":{"styleLess":"font-size: 2.5rem; line-height: 3rem;"},"tiny":{"styleLess":"font-size: 2rem; line-height: 2.5rem;"}},"children":[],"createdBy":"6a524a3cbc0fac0d25bf4b97","origin":null,"selector":null},{"_id":"987ff809-e736-c33d-6163-789bfdb0b039","fake":false,"type":"class","name":"p002-scroll-highlight_mark","namespace":"","comb":"","styleLess":"padding-right: 0.15rem; padding-left: 0.15rem;","variants":{},"children":[],"createdBy":"6a524a3cbc0fac0d25bf4b97","origin":null,"selector":null}],"assets":[],"ix1":[],"ix2":{"interactions":[],"events":[],"actionLists":[]},"expandUserComponents":false},"meta":{"droppedLinks":0,"dynBindRemovedCount":0,"dynListBindRemovedCount":0,"paginationRemovedCount":0,"universalBindingsRemovedCount":0,"unlinkedSymbolCount":0,"codeComponentsRemovedCount":0,"richTextComponentsStripped":false,"sourceSiteId":"6b096dae266175f97ab230b5"}}

Add custom JavaScript

JavaScript
(() => {
  const components = document.querySelectorAll('.p002-scroll-highlight');
  if (!components.length) return;

  // Respect reduced motion preferences.
  if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;

  // Show or hide highlights based on scroll position.
  const observer = new IntersectionObserver(
    (entries) => {
      entries.forEach((entry) => {
        entry.target.classList.toggle('is-visible', entry.isIntersecting);
      });
    },
    {
      rootMargin: '0px 0px -35% 0px',
      threshold: 0,
    },
  );

  components.forEach((component) => {
    // Stagger multiple highlights.
    component.querySelectorAll('.p002-scroll-highlight_mark').forEach((mark, index) => {
      mark.style.setProperty('--p002-delay', `${200 + index * 180}ms`);
    });

    observer.observe(component);
  });
})();

Add HTML structure

<div class="p002-scroll-highlight">
  <p class="p002-scroll-highlight_text">
    We build websites that feel
    <span class="p002-scroll-highlight_mark">alive</span>
    and turn simple layouts into
    <span class="p002-scroll-highlight_mark">memorable</span>
    experiences.
  </p>
</div>

Add custom CSS

.p002-scroll-highlight_mark {
  background-image: linear-gradient(rgba(70, 110, 255, 0.28), rgba(70, 110, 255, 0.28));
  background-repeat: no-repeat;
  background-position: left bottom;
  background-size: 0% 100%;
  transition: background-size 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.p002-scroll-highlight.is-visible .p002-scroll-highlight_mark {
  background-size: 100% 100%;
  transition-delay: var(--p002-delay, 200ms);
}

@media (prefers-reduced-motion: reduce) {
  .p002-scroll-highlight .p002-scroll-highlight_mark,
  .p002-scroll-highlight.is-visible .p002-scroll-highlight_mark {
    background-size: 100% 100%;
    transition: none;
  }
}

Add custom JavaScript

JavaScript
(() => {
  const components = document.querySelectorAll('.p002-scroll-highlight');
  if (!components.length) return;

  // Respect reduced motion preferences.
  if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;

  // Show or hide highlights based on scroll position.
  const observer = new IntersectionObserver(
    (entries) => {
      entries.forEach((entry) => {
        entry.target.classList.toggle('is-visible', entry.isIntersecting);
      });
    },
    {
      rootMargin: '0px 0px -35% 0px',
      threshold: 0,
    },
  );

  components.forEach((component) => {
    // Stagger multiple highlights.
    component.querySelectorAll('.p002-scroll-highlight_mark').forEach((mark, index) => {
      mark.style.setProperty('--p002-delay', `${200 + index * 180}ms`);
    });

    observer.observe(component);
  });
})();

Documentation

How to use in Webflow

‍

Copy the component into your Webflow project. Keep the CSS embed "p002-css" inside the component. Inside this embed there is all the necessary CSS code for the animation.

Publish your page to test the menu and replace the placeholder links with your own destinations.

‍

‍

How it works

‍

Selected words and phrases are highlighted as the text scrolls into view. The effect resets when scrolling away and plays again when the text re-enters the viewport.

‍

‍

How to customize

‍

Edit the text and choose which words or phrases you want to highlight.

‍

‍Webflow: Double-click the text element, select the words you want to highlight, and choose "Wrap in Span". Apply the class "p002-scroll-highlight_mark" to the Span.

‍‍

Code: Wrap the words in a <span> with the class "p002-scroll-highlight_mark".

‍