Parallax scrolling with text fade out on scroll (CSS-only + jQuery)

Inspired by: https://codepen.io/karldanninger/pen/NwzMzN + https://codepen.io/nickcil/pen/sfutl

by xaliber

HTML

<div class="container">

<div class="top" id="top">
  <div class="title" id="title">
    Fade Away
  </div>
</div>

<div class="content">
<p>
Both in jQuery and here, what's scrolling is actually .content, not body.
</p>
<p>
White paper segmentation families granular big data dynamic natural resources energize, vibrant families social return on investment human-centered radical. Inclusive philanthropy design thinking agile, we must stand up ecosystem; support social impact efficient game-changer ecosystem and correlation shared value. Ideate state of play technology circular, disrupt innovation paradigm movements change-makers. Natural resources triple bottom line bandwidth movements venture philanthropy incubator energize effective problem-solvers uplift. Greenwashing we must stand up segmentation, program area; resilient venture philanthropy, academic expose the truth entrepreneur activate transparent venture philanthropy empower communities deep dive. NGO collective impact synergy initiative, bandwidth, storytelling revolutionary inspiring, our work segmentation.
</p>
<p>
Deep dive the resistance, problem-solvers impact investing social entrepreneur indicators inspiring energize. Boots on the ground our work systems thinking think tank innovation. Green space catalyze blended value sustainable empower communities thought partnership.

</p>
<p>
NGO disrupt, expose the truth save the world, black lives matter challenges and opportunities thought leader movements efficient theory of change cultivate activate strategy LGBTQ+. Paradigm; emerging because, a; social enterprise strategy accessibility. Design thinking, segmentation; relief, justice her body her rights gender rights. Catalyze parse inclusion thought leader, overcome injustice, expose the truth collective impact silo ideate.

</p>
<p>
Transparent benefit corporation social impact data families scale and impact social capital a shared unit of analysis. Uplift dynamic; movements, co-creation, co-create,...

CSS

body {
  margin: 0;
  height: 1000px;
  font-family: sans-serif;
  color: #333;
}
.content {
  padding: 10%;
}
p {
  line-height: 1.75;
}

.top {
  margin: 0;
  position: relative;
  width: 100%;
  background-color: #aaa;
  height: 300px;
  opacity: 1;
  text-align: center;
  font-family: 'helvetica';
  font-size: 100px;
  font-weight: 700;
  color: #fff;
}

.title {
  position: absolute;
  top: 60%;
  left: 100px;
  
  /* transition: opacity 0.3s ease;
     Don't need this as the transition is already smooth
  */
}

/* Start parallax, to disable just comment this  */
html, body {
  
  scroll-behavior: smooth;
  overflow: hidden;
}
.container {
  perspective: 1px;
  margin-left: -3px; 
  transform-style: preserve-3d;
  height: 100vh;
  overflow-x: hidden;
  overflow-y: scroll;
}
.top {
  display: flex;
  flex: 1 0 auto;
  position: relative;
  z-index: -1;
  height: 100vh;
  justify-content: center;
  align-items: center;
  transform: translateZ(-1px) scale(2);
}
.content {
  background: rgba(255,255,255,.5);
  position: relative;
  z-index: 1;
}

JavaScript

$(".container").scroll(function() {
    $(".title").css({
    'opacity' : 1-(($(this).scrollTop())/150)
    });          
});