Text Parallax Effect

For my website, I am interested in incorporating a unique parallax effect. Instead of just fixing a background image and allowing scrolling over it, I want to apply this effect to all of the content on my site.

The website consists of a single page with multiple sections. Each section is set to a minimum height of 100vh on landscape screens. When a particular section is in view, users should be able to scroll normally until the bottom of that section aligns with the bottom of the screen. Once the next container begins to enter the viewport, the previous section should become fixed, allowing the new section to slide over it seamlessly like sheets of paper stacking up.

Do you have any suggestions on how to achieve this effect? I don't need fully coded examples, but rather some ideas on how you would approach this design challenge.

Thank you for your help.


Additional Details

I feel like my description may still be vague, so let me elaborate further. Picture having five sheets of paper, each containing different content such as an "About" section or "Features." Each sheet is the height of your viewport, so only one sheet is visible at a time. If the content extends beyond the viewport height, the sheet expands accordingly. As you scroll down the page, instead of the current sheet moving upwards, it remains stationary while the next sheet slides over it like layers of paper.

Answer №1

Maybe you're thinking of something like this?

<main>
  <section class="orange fixed">
    <h2>
      Some text
    </h2>
  </section>
  <section class="blue">
    <h2>
      Some text
    </h2>
  </section>
  <section class="orange">
    <h2>
      Some text
    </h2>
  </section>
</main>

JS:

var $sections = $('main section');
var sectionHeight = $sections.eq(0).outerHeight();
var setCurrent = function(position ) {
    $sections.eq(position).addClass('fixed').siblings().removeClass('fixed');  
}

$(window).on('scroll', function() {
  var scTop = $(window).scrollTop();
  var position = Math.ceil( scTop / sectionHeight );
  setCurrent( position - 1 );

})

And here's some sass code

body {
  margin: 0;
}

main {
  padding: 0;
  padding-top: 100vh; // This is the key point
  section {
    height: 100vh;
    text-align: center;
    color: white;
    padding-top: 200px;
    position: relative;
    margin: 0;
    h2 {
      margin: 0;
      padding: 0;
    }
    &.orange {
      background: orange;
    }
    &.blue {
      background: blue;
    }
    &.fixed { // This is important
      position: fixed;
      left: 0;
      top: 0;
      width: 100%;
    }
  }
}

You can try it out here

https://jsfiddle.net/3r1Lm4ha/8/ (Possibly more recent)

Note: There may be room for improvement, but I hope this aligns with what you had in mind

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The error message states: "An uncaught TypeError has occurred - the object does not possess the 'jqzoom' method."

I am encountering a browser console error while working on a project involving a magento website. Specifically, I need to implement the jqzoom feature on the product view page. Here's what I have done so far: Added jQuery Included the jqzoom librar ...

Trouble with closing Bootstrap 4 modal

My Bootstrap 4 modal is causing issues as it pops up on button click but won't close unless I refresh the page. I've been attempting to get it to close by clicking the 'close' button or simply by clicking anywhere on the main page body. ...

Can you explain the distinction between [att|=val] and [att~=val] in css?

Could someone help me differentiate between the [att|=val] and [att~=val] attributes in CSS? I'm having trouble grasping the concept. Thank you! ...

The ng-view in index.html is not being loaded by AngularJS

I've been working on setting up a single-page application using AngularJS. In my setup, I'm using Node with Express and have an Apache server functioning as middleware. The issue I'm facing is that while my index.html page loads without any ...

Render a select field multiple instances in React

I have 5 different labels that need to be displayed, each with a select field containing the options: string, fixed, guid, disabled Below is the code I've written: class CampaignCodeRenderer extends Component { state = { defaultCampaigns: ...

Exclude the node_modules directory when searching for files using a global file pattern

I'm facing some challenges setting up a karma configuration file because I am having difficulty creating a glob that correctly matches my files. Within my lerna repository, there may be node_modules folders inside the packages, and it's importan ...

Retrieving data from NodeJS ExpressJS variables

Hey fellow developers, Currently, I'm working with Express and Ajax to transfer data from the client to NodeJS. I am struggling with a situation where my variable seems to be undefined outside of the function. I would really appreciate it if someone ...

Addressing a jquery.ajax relative path problem

I am a newcomer to this topic and I have been researching extensively online for more information. I would like some further insight into the following issue: I am attempting to retrieve a JSON file located one level down from the directory where `index.h ...

Vue components are failing to appear in the live environment, however they function perfectly in the development environment

My Laravel Vue project runs smoothly in development, but on the live shared hosting server, the vue components are not displaying. However, the Laravel views function correctly with no errors in the console. I have already run npm run production to minif ...

What is the best way to exclude input elements that have either an empty value or no value attribute specified?

I've come across a dilemma regarding a jQuery function I'm using for submitting a search form. The function disables empty fields so they are not submitted with the form, preventing them from being added to the query string in the URL: $('f ...

Guide on integrating a JavaScript control (JavaScript package) obtained from GitHub into my asp.net application

Hello everyone, I am a newcomer to GitHub and have some basic questions to ask. Recently, I downloaded the package from https://github.com/jspreadsheet/ce in .zip format for using in my asp.net web application. However, I am not sure how to incorporate the ...

Hide the overlay fullscreen menu upon clicking an anchor link

I'm having trouble with Javascript, but some of you might find this easy. I found a fullscreen overlay menu on Codepen and I'm trying to figure out how to close it when clicking an anchor link. Looking for assistance with adding javascript to c ...

Displaying a blank column in a table using JavaScript

I am trying to write a JavaScript function that will add a new column to a table. I want this new column to be displayed at the index where it is added, and then hidden once the addition is complete. Here is the code for my method: function addColumnToTa ...

Issue with mobile browser validation for text field functionality not functioning properly

Issue with text box validation on mobile browsers for my Angular application Mobile Browsers: Chrome, Samsung Browser (not working in both) Expected Input: Numbers 0-9 and Alphabets A-Z only in the text field My Approach : 1. Initial Attempt: I attempted ...

Is there a way to adjust the position of the scrolling bar to be closer to the post area?

I was exploring this page (http://noahsdad.com/state-fair-texas-2011/) and noticed a scrolling sidebar to the left of the content area. I'm looking to adjust it so that it is closer to the content area. Any suggestions on how to achieve this? Thank y ...

It appears that the JS function is not being triggered

I am facing an issue with my JavaScript code where a ball is not showing up even though it should. I have an array with only one element, and when that element matches with "F2", the ball is supposed to appear. I suspect there might be a problem with my us ...

Django is indicating that the path is not reachable

I've been struggling with a seemingly silly issue in my code. I can't figure out why it's not working properly. Here is the directory structure of my Django Project: https://i.sstatic.net/0tVo4.png The HTML file I'm targeting (index.h ...

extracting ID values from a looped table with the use of PHP and JavaScript

I've been experimenting with PHP and MySQL to create a table, here's what I have so far... PHP :- foreach($result as $res){ echo '<tr><td style="display:none;"><p id="ID">' . $ID . ' </p></td&g ...

How can I smoothly navigate to the top of a page using AngularJS?

After receiving an ajax call response using angularjs, I am looking to automatically scroll to the top of the page. The purpose is to bring focus to alert messages displayed at the top of the page upon receiving the ajax response. Appreciate any guidance ...

What is the solution to the error "Maximum update depth exceeded. Calls to setState inside componentWillUpdate or componentDidUpdate" in React?

Everything was running smoothly until this unexpected issue appeared. I attempted to change the condition to componentDidMount, but unfortunately, that didn't resolve the problem. The error is occurring in this particular function. componentDidUpd ...