Browse through different backgrounds while a single background remains still for multiple scroll actions

I am trying to create a specific scrolling effect on my webpage:

Upon loading the page, I want a div with background1.png to be displayed. As the user starts scrolling, I want this div to remain fixed for a predetermined amount of scroll movements. Once these movements are completed, the scrolling should continue and reveal a second div.

Here is a basic solution I have attempted, although I'm not sure if it's the right approach:

$(function() {  

    var staticSet = false;

    $(window).scroll(function() {            

        var currentScroll = $(window).scrollTop(); 

        if(currentScroll > '589' && staticSet == false){      
            staticSet = true;
            $('.calder').css('position','static');                                                              
        };                                                              
    });     
});

Essentially, I initially set the first div to position:fixed, and once the scrolling reaches a specific value, I change the div to static. However, this method does not provide a smooth transition between the two divs.

Answer №1

Utilizing background-position: fixed allows you to keep the background stationary as you scroll.

Check out this example on a fiddle: http://jsfiddle.net/abc123/

I'm unsure if this solution addresses your specific issue, though.

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

Preventing the element from breaking when it is not the child: Tips and Tricks

In order to align both .quote-container and #new-quote elements in the same line, even when the window width is very small (e.g., 83 pixels), I used min-width on the .quote-container element successfully. However, applying the same technique to the #new-qu ...

Finding a specific cell in a Django HTML table: tips and tricks

Recently delving into django and its intricacies. Struggling to grasp the concept of accurately pinpointing a specific cell within an html table. Yearning to modify the background color of select cells based on certain conditions derived from the generate ...

Kendo UI Web - MultiSelect: choosing an option multiple times

Currently, I am encountering an issue with the Kendo UI MultiSelect widget when trying to select an option multiple times. An example of this is shown in the image below where I want to choose Schindler's List again after selecting The Dark Knight. Ho ...

"Exploring the New Features of Bootstrap 5: Button Collapse and

I am struggling to get two buttons working with Bootstrap 5. The first button is supposed to trigger two JavaScript functions to open a bootstrap carousel. The second button is a simple collapse button designed to reveal a long text string. Unfortunately, ...

Refresh the html of the contenteditable element with the most recent targeted information from the textarea

One issue I'm encountering is quite straightforward: selecting/focusing on a few contenteditable elements, then selecting the textarea and changing the HTML of the last focused element from the textarea. However, my problem arises when the textarea tr ...

Performing a task through an AJAX call in DNN MVC

During my DNN MVC development journey, I encountered another issue. I am unsure if this is a bug, a missing feature, or a mistake on my part. Let me elaborate on the problem below. My Objective I aim to trigger an action in my controller by making an AJA ...

Tips on altering CSS attributes within Magnific Popup

I am currently utilizing the Magnific Popup plugin in my project. The code snippet I have implemented is as shown below: $(".event").magnificPopup({ items: { src: ".hidden-div", type: "inline" ...

Encountering issues when attempting to post JSON form data to a REST API via AJAX within a React

Recently, I created a basic SignUp page utilizing React and I am looking to transmit the form data to a REST API. In my setup, I have incorporated react.min.js, react-dom.min.js, and jquery.min.js. Here is the code snippet: <div id="container"></ ...

Transform the look of your bootstrap 5 inputs by making them dark-themed

I have a feature in my app that allows users to switch between light and dark modes. Currently, I am using Bootstrap 5 form-control inputs and want to customize their background color based on the mode selected. Which CSS classes do I need to target in or ...

Incorporating visuals into Doxygen documentation

Struggling to add an image with a caption in a doxygen .md file. Adding a caption is easy, but aligning the image left is proving difficult. I've tried several methods, but none have worked successfully. ![Caption](my_image.png "Caption") R ...

jQuery counter no longer updates when scrolling

I'm having trouble with my jQuery counting function when using the scroll feature on a specific div ID. The numbers freeze if I keep scrolling before they finish updating on the screen. Whenever I scroll to the defined div ID, the counting function k ...

Achieve an overlapping effect with grid items

I'm in the process of creating a CSS grid layout where the header overlaps the next row. Below is a snippet of my code with the header positioned on top, and the linked image should give you an idea of what I'm aiming for. Thank you! https://i ...

splitting up the lengthy list into manageable chunks according to the screen dimensions

How can I make the blue color row-based list (the divs inside a div with id phrase) break on the next line based on the screen size? Any suggestions on additional changes needed in the following CSS? #phrase { color: #fff; position: ...

Choose gets stuck while loading an abundance of data using JQuery's .html() and JSON

Here's the code snippet I'm currently using: $.getJSON("registro/backend.php?action=list&id="+sel.value, function(data){ var options = []; for (var i=0; i<data.rows.length; i++) { options += &apos ...

"Adding a next button to a jQuery mobile detail page is a simple process that can

Is it possible to add a "next" button on a detail page in order to navigate to the next detail page? I am new to jqm and wondering if there is a way to achieve this without requesting json data on every page load. Any suggestions or solutions would be grea ...

identify when the React component has reached the bottom of the element by reading the

Is there a way to access the scroll handler's event without being able to access offsetTop, scrollTop, etc? class App extends React.Component { handleScroll = e => { console.log(e.target.scrollTop); }; componentDidMo ...

Having issues with implementing the "return to top" functionality using Jquery. Require assistance in resolving the problem and refreshing the

I have encountered an issue with my website while trying to add a "back to top" feature. I have spent the entire day trying to fix it, but unfortunately, I haven't been able to find a solution. I am hoping that someone here can lend me a hand. Proble ...

Troubleshooting problems with text areas in Android when using JQueryMobile and PhoneGap

When viewing my textarea control, I noticed that it breaks away from the .css theme and displays two boxes - one themed and one not. This issue only occurs on my HTC Evo device, as the code works fine on the emulator. You can see a screenshot of this behav ...

The relationship between columns in MySQL is determined by the values they hold

I have 2 tables with the following structure: mysql> select * from customer; +-------+-------+ | name | code | +-------+-------+ | John | c1 | | Mary | c2 | | Sarah | c3 | +-------+-------+ mysql> select * from supplier; +-------+----- ...

IE8 - Unable to use rgba()

I'm currently facing an issue with RGBA() manipulation in jQuery while using IE 8. Here's the code I have so far: $('.set').click(function (e) { var hiddenSection = $('div.hidden'); hiddenSection.fadeIn() . ...