Stacking components when scrolling in CSS to create a scrolling effect

I've been attempting to replicate the scrolling animation seen on this particular website: . The effect involves keeping the previous content in place while new content stacks on top as you scroll. I have experimented with using position:sticky and adjusting the z-index for each element, but so far it has not yielded the desired outcome. Does anyone know how to achieve this scrolling effect using CSS?

Source: https://codepen.io/daniel5120/pen/PoEoaEP In essence, I am looking to maintain the original placement of the contents within the first container while allowing the second element to overlay the first.

Answer №1

Unfortunately, the code you provided on codepen did not function properly with the position: sticky property because of the specified height in the html and body elements. If you are interested in understanding why this occurred, I recommend checking out this explanation on Stack Overflow.

To view the modified version of your code on codepen, please click here.

In order to illustrate why your original code did not work as intended, I have created a sample example below:

html, body {
    margin: 0px;
    padding: 0px;
}

.pages {
    position: sticky;
    width: 100%;
    height: 100vh;
        top: 0;
    
    display: inline-block;
    padding: 10px;
    box-sizing: border-box;
}
<div class="pages" style="background-color:red;">
    <h1>Title RED</h1>
    <img src="https://picsum.photos/400/100?random=1">
</div>

<div class="pages" style="background-color:yellow;">
    <h1>Title YELLOW</h1>
    <img src="https://picsum.photos/400/100?random=2">
</div>

<div class="pages" style="background-color:blue;">
    <h1>Title BLUE</h1>
    <img src="https://picsum.photos/400/100?random=3">
</div>

<div class="pages" style="background-color:green;">
    <h1>Title GREEN</h1>
    <img src="https://picsum.photos/400/100?random=4">
</div>

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

Is there a way to relocate the play again button below the box?

How can I ensure that my "Play Again" button moves up to align perfectly under the black border box? The black border box is styled with a class named .foot .button { background: rgb(247, 150, 192); background: radial-gradient(circle, rgba(247, 1 ...

The jQuery functions properly offline, but fails to load when connected to the

I am encountering an issue with the following script: <script type="text/javascript"> $.getJSON("http://api.twitter.com/1/statuses/user_timeline/koawatea.json?count=1&include_rts=1&callback=?", function(data) { $("#headertweet") ...

Implementing jQuery functionality on elements that are generated dynamically

I'm facing a challenge when working with dynamic elements in jQuery and I really could use some help. Let me provide an example from my current project: main.js $(function () { renderPlaceList(places); setupVoting(); } The two functions are ...

sliderLighter: keep the slider moving smoothly at a constant speed

I am currently utilizing lightSlider and I want to create a continuous sliding effect with consistent speed. I do not want any stops or pauses between the images, just a smooth and constant movement. Is it possible to achieve this using lightSlider? Or per ...

How can a server retrieve a file uploaded using FormData and Ajax on a cross-domain upload?

my website is running on localhost:8084 and I need to upload a file to localhost:8086. Below is the JavaScript code: var xhr = new XMLHttpRequest(); xhr.open("post", "http://localshot:8086"+ "?type=ajax",true); xhr.setRequestHeader("X-Reque ...

Leverage the geocode callback function results from Google Maps in NodeJS to render a map on the AngularJS 2 component template

Hey there, I'm currently utilizing the Google Maps Node.js client web API and want to showcase a map on my HTML views using AngularJS 2. I have a server export that sends an object to my AngularJS2 client service const googleMapsClient = require(&ap ...

Upon clicking the checkbox, only the ul tag will be displayed on the screen

It's puzzling to me that when I click on the checkbox, only the ul tag with id=menu is visible on the screen, not id=social. I need to ensure display:block is set for every ul tag. .show-menu { display:block; } #menu{ float:left; } #social{ ...

Tips for achieving a slanted div design

Is there a way to create a slanted div similar to the red div shown on this website? Below is the CSS I have attempted: #parallelogram { width: 150px; height: 100px; -webkit-transform: skew(20deg); -moz-transform: skew(20deg); ...

Adjusting the height of the Sencha Touch container to accommodate its content

In Sencha Touch, I have a view that generates a popup box from the right when a button in the bottom toolbar is clicked: Ext.define('TheApp.view.PopupTablet',{ extend: 'Ext.form.Panel', xtype: 'popupbox', confi ...

The Ruby on Rails application is having trouble detecting the stylesheet in the assets

I'm having some trouble displaying a border on my buttons. The button styles are defined in the app/assets/stylesheets/modules/_buttons.scss file, which I have imported into application.scss. @import "bootstrap-sprockets"; @import "bootstrap"; //m ...

In order to ensure JavaScript can be universally applied to all images, it needs to be made more generic

I have developed JavaScript functions to enable zoom in and zoom out functionality for an image through pinching gestures. Now, I aim to refactor the code below so that I can include it in a shared JavaScript file. var scale = 1; var newScale; ...

The color of the Angular md-switch .md-thumb is not showing up properly when switching the toggle

In Safari, the md-switch displays a yellow section on the md-thumb when toggled. However, other browsers handle the switch without any issues. The md-bar appears fine, but the md-thumb is yellow. I have tried setting everything to the blue color I am using ...

Exploring the wonders of Html5 Canvas with base64 encoded images

I have a base64 encoded image that looks like this: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUAAAADwCA...... Is there a way to draw this on a canvas using the encoded image provided above? Does anyone have an example of how to do this? Updated: ...

Express handlebars does not support client-side javascript

This is a unique template <html lang="en"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>My Amazing Website</title> ...

Integrate a feature in your form that allows users to preview and edit their submission before finalizing

I've set up my HTML form with the following structure: <div class="container"> <div class="form-group" ng-controller="studentController"> <form role="form" class="well form-horizontal" id="registerForm" name="forms.register ...

Begin anew with Flip.js

Currently, I am incorporating the jquery flip plugin from nnattawat.github.io/flip to establish a card flipping mechanism on my website. I have successfully implemented the method outlined in the documentation to unregister the flip event from the elemen ...

Is it possible to create an index.html page with all the necessary head tags to prevent duplicate code across multiple html pages?

Imagine I am using app.js or a Bootstrap CDN link for all of my HTML pages, but I don't want to include it in every single page individually. Is there a way to create an index.html file that includes this so that all other HTML pages load the head fro ...

Extract information from a constantly changing HTML webpage using Java

Is there a way to retrieve data from the Live Cyber Attack website? I am looking to extract specific information such as Time, Type of Attack, Attacking Country, and Target Country. I need this data to be dynamic for analysis purposes. Currently, I am wo ...

Showing dynamic html based on conditions using Knockout

I am working with a knockout observable array that contains both audits and comments. After receiving the data from the server, I have sorted the array based on the timestamp of the objects. My goal is to display html conditionally based on the type of ac ...

What is the most effective way to eliminate the title from any tag?

How can I remove the title from only page-1 while using the same structure for both page-1 and page-2? I need to keep the same code structure for both pages, but I want to remove the title that is shown in the hover state. Any help is appreciated. Thanks i ...