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

              
                
<body>
	  <!-- Summer is approaching, and the June #CodePenChallenge has just kicked off! So why not celebrate with a
  (smoothly) scrollable rainbow smoothie? The recipe is refreshingly easy: vibrant colors, healthy ingredients, positive vibes, and, of course, smooth scrolling! Plus, it's a great opportunity to experiment with Scrollspy :)
  | CodePen Challenge, June 2024, "Smooth Scrolling" -->
  <header id="header">
    <div class="page-title">
      <h1>Rainbow Smoothie</h1>
    </div>
  </header>
  <main>
    <nav id="navbar">
      <ul class="nav">
        <li class="nav-item">
          <a class="nav-link emoji" href="#purple" aria-label="blueberries">🫐</a>
        </li>
        <li class="nav-item">
          <a class="nav-link emoji" href="#green" aria-label="kiwi">🥝</a>
        </li>
        <li class="nav-item">
          <a class="nav-link emoji" href="#yellow" aria-label="banana">🍌</a>
        </li>
        <li class="nav-item">
          <a class="nav-link emoji" href="#orange" aria-label="orange">🍊</a>
        </li>
        <li class="nav-item">
          <a class="nav-link emoji" href="#red" aria-label="watermelon">🍉</a>
        </li>
      </ul>
    </nav>
    <div class="smoothie">
      <div id="straw"></div>
      <div data-bs-spy="scroll" data-bs-target="#navbar" tabindex="0" class="scrollspy glass">
        <div id="purple" class="layer">
          <div class="info">
            <h4>Blueberries</h4>
            <p>(rich in antioxidants)</p>
          </div>
        </div>
        <div id="green" class="layer">
          <div class="info">
            <h4>Kiwi</h4>
            <p>(source of fiber)</p>
          </div>
        </div>
        <div id="yellow" class="layer">
          <div class="info">
            <h4>Banana</h4>
            <p>(high in potassium)</p>
          </div>
        </div>
        <div id="orange" class="layer">
          <div class="info">
            <h4>Orange</h4>
            <p>(for Vitamin C)</p>
          </div>
        </div>
        <div id="red" class="layer">
          <div class="info">
            <h4>Watermelon</h4>
            <p>(high water content)</p>
          </div>
        </div>
      </div>
    </div>
    <div id="backtop">
      <a class="backtop-link emoji" href="#header" aria-label="backtop">👆</a>
    </div>
  </main>
  <footer id="footer">
    <div class="page-bottom">
      <p>Thanks for scrolling!</p>
      <p class="grey">#cpc-smooth-scrolling</p>
    </div>
  </footer>
</body>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,200..800&display=swap');

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

:root {
  --item-width: 500px;
  --purple: #4a00f0;
  --green: #24b760;
  --yellow: #ecd200;
  --orange: #ff9900;
  --red: #f10000;
  --grey: #888;
  --title: 2.5rem;
  --text: 1rem;
  --emoji: 2rem;
}

@media only screen and (max-width: 600px) {
  :root {
    --item-width: 400px;
    --title: 2rem;
  }
}

@media only screen and (max-width: 500px) {
  :root {
    --item-width: 280px;
    --title: 1.5rem;
    --emoji: 1.5rem;
  }
}

html {
  width: 100%;
  height: 100%;
  font-family: "Bricolage Grotesque", sans-serif;
  font-optical-sizing: auto;
  font-style: normal;
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

body {
  background-color: #000;
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  color: #fff;
  position: relative;
}

h1,
h2,
h3,
h4,
h5,
h6,
p {
  margin: 0;
}

h1 {
  font-size: var(--title);
}

p {
  font-size: var(--text);
}

a {
  color: #fff;
  font-size: var(--emoji);
  text-decoration: none;
  transition: all .15s ease;
}

a.emoji {
  font-size: var(--emoji);
  text-decoration: none;
}

a:hover,
a.active,
a:active,
a:focus {
  text-shadow: 0px 0px 10px #fff, 0px 0px 10px #fff;
}

.grey {
  color: var(--grey);
}

.page-title,
nav {
  width: var(--item-width);
  margin: auto;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  overflow: hidden;
  text-align: center;
}

.page-title {
  padding-top: 10px;
  border: .5px solid rgba(255, 255, 255, 0.3);
  border-top: 0;
  border-bottom: 0;
}

nav {
  position: -webkit-sticky;
  position: sticky;
  top: 0px;
  padding: 10px 0 15px;
  border: .5px solid rgba(255, 255, 255, 0.3);
  border-top: 0;
  border-radius: 0 0 100px 100px;
  z-index: 999;
}

nav ul {
  padding: 0;
  margin: 0;
  list-style: none;
  display: flex;
  justify-content: center;
  gap: 2rem;
}

footer {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
}

#backtop {
  display: none;
  opacity: 0;
  position: -webkit-sticky;
  position: sticky;
  bottom: 0px;
  width: var(--item-width);
  padding: 15px 0 10px;
  margin: auto;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 100px 100px 0 0;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  border: .5px solid rgba(255, 255, 255, 0.3);
  border-bottom: 0;
  text-align: center;
  z-index: 999;
}

#backtop.show {
  display: block;
  opacity: 1;
}

.page-bottom {
  text-align: center;
  width: var(--item-width);
  margin: 0 auto;
  padding-bottom: 15px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 0;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  border: .5px solid rgba(255, 255, 255, 0.3);
  border-top: 0;
  border-bottom: 0;
}

.page-bottom p {
  margin: 0;
}

.smoothie {
  margin-top: 170px;
  margin-bottom: 200px;
}

@media only screen and (max-height: 500px) {
  .smoothie {
    margin-top: 40px;
  }
}

.smoothie,
.glass {
  position: relative;
}

.glass {
  width: calc(var(--item-width) + 20px);
  height: 100%;
  padding: 200px 10px 10px;
  margin: auto;
  z-index: 1;
}

.glass:after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  background: linear-gradient(90deg,
      rgba(255, 255, 255, 0.5) 0%,
      rgba(255, 255, 255, 0.9) 10%,
      rgba(255, 255, 255, 0.5) 25%,
      rgba(255, 255, 255, 0.2) 40%,
      rgba(255, 255, 255, 0.2) 60%,
      rgba(255, 255, 255, 0.5) 75%,
      rgba(255, 255, 255, 0.9) 90%,
      rgba(255, 255, 255, 0.5) 100%);
  opacity: .5;
  border-radius: 0 0 100px 100px;
  border: .5px solid #fff;
}

.glass:before {
  content: "";
  position: absolute;
  width: calc(100% - 20px);
  height: calc(100% - 210px);
  left: 10px;
  bottom: 10px;
  filter: contrast(170%) brightness(100%);
  background-image: url('data:image/svg+xml,<svg viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg"><filter id="noiseFilter"><feTurbulence type="fractalNoise" baseFrequency="4.02" numOctaves="4" stitchTiles="stitch"/></filter><rect width="100%" height="100%" filter="url(%23noiseFilter)"/></svg>');
  z-index: 1;
  opacity: .3;
  border-radius: 0 0 95px 95px;
  background-position: 0 0;
  transform: translateZ(0);
  animation: texture 10s linear infinite;
}

@media (prefers-reduced-motion: no-preference) {
  @keyframes texture {
    to {
      background-position: 0 -10%;
    }
  }
}

#straw {
  width: 24px;
  height: 400px;
  margin: auto;
  margin-bottom: -180px;
  transform: rotate(7deg) translate(150px, 5px);
  z-index: -2;
  background: linear-gradient(0deg, var(--red), var(--purple), var(--green), var(--yellow), var(--orange), var(--red));
  background-size: 200% 200%;
  background-position: 0% 0%;
  animation: rainbow 3s linear infinite;
}

@media (prefers-reduced-motion: no-preference) {
  @keyframes rainbow {
    to {
      background-position: 200% 200%;
    }
  }
}

#straw::after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.5) 10%, white 30%, rgba(255, 255, 255, 0.5) 50%, transparent);
  opacity: .5;
}

@media only screen and (max-width: 600px) {
  #straw {
    transform: rotate(7deg) translate(100px, 15px);
  }
}

@media only screen and (max-width: 500px) {
  nav ul {
    gap: 1rem;
  }

  #straw {
    transform: rotate(7deg) translate(90px, 20px);
  }
}

.layer {
  position: relative;
  height: 100vh;
  margin-bottom: 30%;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all .3s ease;
}

.layer:last-child {
  margin-bottom: 0;
}

.layer .info {
  text-align: center;
  font-size: 2rem;
  margin-bottom: 20%;
  filter: blur(100px);
  transition: all 1s ease;
  z-index: 9;
}

.layer.active .info {
  filter: blur(0px);
  transition: all .4s ease;
}

.layer:after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  padding-bottom: 30%;
  top: 0;
  left: 0;
  box-sizing: content-box;
}

#purple:after {
  background: linear-gradient(180deg, var(--purple) 70%, var(--green) 99%, var(--green));
}

#green:after {
  background: linear-gradient(180deg, var(--green) 70%, var(--yellow) 99%, var(--yellow));
}

#yellow:after {
  background: linear-gradient(180deg, var(--yellow) 70%, var(--orange) 99%, var(--orange));
}

#orange:after {
  background: linear-gradient(180deg, var(--orange) 70%, var(--red) 99%, var(--red));
}

#red:after {
  background: var(--red);
}

#red:after,
#red:before {
  padding-bottom: 0;
  border-radius: 0 0 95px 95px;
}
              
            
!

JS

              
                console.clear()

var scrollSpy = new bootstrap.ScrollSpy(document.body, {
	target: '#navbar'
});

let navLinks = document.querySelectorAll('a.nav-link'); 
let sections = document.querySelectorAll('.layer');
const backtop = document.getElementById("backtop");

let sectionData = Array.from(sections).map(section => {
    return {
        element: section,
        id: section.getAttribute('id')
    };
});

const firstScrollSpyEl = document.querySelector('[data-bs-spy="scroll"]');
firstScrollSpyEl.addEventListener('activate.bs.scrollspy', (e) => {
    let activeSectionId = e.relatedTarget.getAttribute('href').substring(1);
    let activeSection = sectionData.find(section => section.id === activeSectionId);
    if (activeSection) {
        sectionData.forEach(section => section.element.classList.remove('active'));
        activeSection.element.classList.add('active');
    }
});

window.onscroll = function () {
	if (document.body.scrollTop > 50 || document.documentElement.scrollTop > 50) {
		backtop.classList.add("show");
	} else {
		backtop.classList.remove("show");
		sectionData.forEach(section => section.element.classList.remove('active'));
	}
}
              
            
!
999px

Console