The single div's parallax effect

Parallax may not be the best term to explain what I'm aiming for, but I am struggling to find an alternative way to phrase it.

Essentially, I have a header section that remains fixed, allowing the rest of the page to slide over the top as intended.

However, I would like to implement a similar section in the middle of the page.

The sequence of events I am trying to accomplish is:

  1. - User at the top of the page with the header fully visible and taking up the full height
  2. - User scrolls down, causing the content of the page to slide over the header
  3. - When the user reaches LAYER A near the top of the page, this layer should remain fixed in position
  4. - As the user continues scrolling down the page, LAYER B (the rest of the page) should continue to slide over LAYER A, leaving only about 75px of the div visible

I have created an image to illustrate this concept.

I attempted to use relative positioning with transform, but it did not work as desired. Ideally, I would like to achieve this effect using only CSS, although I am open to utilizing jQuery if necessary.

Thank you in advance for any assistance!

EDIT 2: I have managed to achieve the desired effect after possibly overthinking it. While my solution may be somewhat hacky and there could be better methods, I was able to accomplish this using the following code:

$(window).scroll(function() {

if ($(".nav_bar").offset().top > 1057) {
    $(".fixedsection_wrapper").addClass("fixedposition"); }
else {
    $(".fixedsection_wrapper").removeClass("fixedposition");
}
});

This simply applies 'position: fixed' to "Layer A" when it intersects with the nav bar, resulting in behavior consistent with the diagram.

Answer №1

Throughout my experience, I have come across numerous parallax scripts that I have utilized for different projects. It typically requires a significant amount of time and effort to customize these scripts to fit my preferences, so it is advisable to experiment with either your own script or someone else's.

In general, these scripts usually focus on the parent element, allowing the code to adjust the distance between the parent and its child div layers accordingly.

For instance:

If Parent A encompasses Children B, C, D. If you wish to implement Parallax effect specifically on "C". You would need to modify the distance between B and D in order to create the desired effect, often achieved by moving the background-image of C upwards as you scroll, while simultaneously adjusting the gap between B and D. As you scroll, D will alter its position at a faster rate than B, and C will transition at an approximate 1:2 ratio.

In summary, when utilizing a parallax script, most adhere to this structure. One potential solution to your issue could involve nesting your Parallax content within a containing element, followed by two additional div elements with relevant content. While this may oversimplify the problem you are facing, it has been effective in addressing similar challenges I encountered in the past.

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

I am seeking a way to eliminate double quotation marks from a string without using the replace function

I need assistance in removing double quotes from the string "Hello". I have an array var ary = ['a', 'b' , 'c'] When I extract a value from the array, it returns the value in string format, such as ary[0] = "a", but I want i ...

HTML 5 File selection on iOS and Android using Cordova/Phonegap

I attempted to utilize the camera in a PhoneGap app using the HTML5 input tag as shown below. Create a new project through CLI Add iOS and Android platforms Incorporate the camera plugin Build for both devices Run on iPhone 5 with iOS 7.1.2 and Samsung N ...

Encountering a null sessionId exception with Selenium RC while attempting to activate the JQuery AddLocationStrategy feature

I've been struggling all day to activate JQuery locators in Selenium RC by trying various suggestions found online, but unfortunately, without any success. I followed the recommendations from this thread on enabling JQuery locators: How do I add a JQ ...

Update the text on a button using a different button

function modify_button_text(){ //update the word from cat to dog. } <button id="button_1_id" >Cat</button> <br><br><br><br> <button id="modify_button_text_btn" >Change the Text of Above Button</button> ...

Click here for a hyperlink with an underline that is the same width

As we work on our website, we want a unique feature where links are underlined when hovered over, with the underline staying the same width regardless of the length of the link text. How can we achieve this using CSS/jQuery/Javascript? ...

In Bootstrap 4, what is the opposite of the .flex-fill class?

Referencing the documentation found here: https://getbootstrap.com/docs/4.1/utilities/flex/#fill I am looking to have a flex element only fill on devices smaller than sm (matching my column breakpoint in the example). Therefore, I thought of using someth ...

Is there a way to address the sporadic behavior of rxjs combineLatest when used in conjunction with ReplaySubject

My current struggle lies within this particular example: const r1 = new ReplaySubject(2); const r2 = new ReplaySubject(2); r1.next('r1.1'); r1.next('r1.2'); r2.next('r2.1'); combineLatest([r1, r2]).subscribe(console.log); // ...

Custom sample rate options in RecordRTC allow for the recording of silent audio tracks

I am currently working on implementing RecordRTC.js to capture audio from a microphone and then upload it to a server built with nancyfx. Initially, I am simply aiming to upload the audio stream and store it in a wav file for testing purposes. However, my ...

How can you position an image and text side by side without specifying the width using a div?

Having some trouble aligning an image (which is contained in a div) and some text (also in a div) on the same line without setting a width for the text. Here's what I've tried so far. <div id="container"> <div id="image" style="flo ...

Can you explain the use of the "left" and "right" fields in the jstree jQuery plugin?

Currently, I am working on creating a tree using the jquery plugin jstree. While going through this plugin's database file, I came across two fields called "left" and "right". However, I am unclear about how these fields are utilized. Interestingly, ...

Is there a way to incorporate unique shapes into mxGraph?

What is the process for including custom shapes in mxgraph? Image Representation of Shapes Check out these BPM shapes ...

Having trouble with the image not showing up using the code <img src="">

UPDATE :: I recently discovered that there is a permission error preventing me from accessing images in the images folder. It seems that I do not have the necessary "permission" to retrieve the image files ... * A few days ago, I posted a question regardi ...

CSS not being applied properly in Devise(Rails) emails when sent to Gmail addresses

Upon a user signing up, I send a confirmation email using Devise's mailer view. While everything else appears to be functioning properly, the CSS for CONFIRM ACCOUNT doesn't seem to be applied at all. I've read that CSS classes cannot be use ...

Enhancing highcharts gauge with dynamic data from JSON

I've been working hard to get my Gauge looking just right, and now I'm attempting to update it with JSON data from Thingspeak. However, when I check the page, I keep running into a ReferenceError - it says "data is not defined." If you want to t ...

Utilize Javascript to extract and showcase JSON data fetched from a RESTful API

I'm attempting to use JavaScript to pull JSON data from a REST API and display it on a webpage. The REST call is functioning correctly in the Firefox console. function gethosts() { var xhttp = new XMLHttpRequest(); xhttp.open("GET", "https://10 ...

Troubleshooting Problem with Accordion Size in CSS

I am facing an issue with a dropdown menu that I have created. The dropdown has parent and child rows to display controls, but the width of the Accordion is not stretching as expected despite being set to 100%. Using Chrome and Edge developer tools, I insp ...

JavaScript & PHP syntax

Trying to pass PHP into a JavaScript variable. I attempted using the div method with the following code snippet: <div class="service-container" data-service="<?php echo bp_loggedin_user_domain() . BP_XPROFILE_SLUG . '/change-avatar/'; ...

React.js removing one of several displayed elements

Just starting out on my todo app project. I've got the functionality where clicking the plus button adds a new task to the list. However, I'm facing an issue with the delete icon - it's deleting all tasks instead of just the one it belongs t ...

What is the best way to use an ID to call a Class in a Script?

Here is the current code I have: <script> window.addEventListener("load", function() { document.getElementsByClassName("but")[0].addEventListener("click", function(e) { // e.preventDefault(); // if it i ...

"Step-by-step guide on integrating social media sharing features with Facebook and Twitter using Angular

I've been working on implementing a Facebook and Twitter share functionality in my Angular app, but I'm struggling to figure it out. After reading through the documentation here: https://developers.facebook.com/docs/sharing/reference/share-dialo ...