A series of divs continuously scrolling in succession with a stationary title/header

My web page contains multiple div sections, each with its own content. I need the page to load initially with all sections visible. Then, I want the page to auto-scroll so that the header of the first section remains fixed while its contents scroll. Once the first section's contents end, the header of the second section replaces it and its contents start scrolling. This process continues until all sections have been shown, and then it starts again with the first section. Can someone guide me on how to achieve this?

You can find my code here: http://pastebin.com/EAYtsWAT

I am currently using jsscroller for automatic content scrolling. While I am able to scroll the contents, I'm unsure how to keep the header of each section fixed as the contents scroll, swapping headers as each section ends.

Answer №1

Upon organizing the code provided and migrating it to jsfiddle, I have crafted a solution that should meet your requirements.

Due to the limited functionality of jscroller, certain adjustments were necessary to achieve the desired outcome:

function SectionManager(){
    this.currentSection = null;
    this.sections = $("#content .section");
    this.numSections = this.sections.length;

    this.transition = function (current){
            //SCROLLER CODE INITIATED HERE....
             $jScroller.config.refresh = 100;
            // Add Scroller Object
            $jScroller.config.obj = [];
            $jScroller.add(
                "#content .section.active .activityTbl",
                "#content .section.active .activityTbl > table",
                "up",
                3
            );
            // Start Autoscroller
            $jScroller.start();
            $jScroller.cache.init = true;
            //SCROLLER CODE CONCLUDED HERE....
    };
    this.callback = function (){
        this.currentSection = (this.currentSection != null)
            ? (this.currentSection + 1) % this.numSections
            : 0
        ;
        $("#content .section").removeClass("active");
        $("#content .section:eq(" + this.currentSection + ")").addClass("active");
        this.transition();
    }

    this.run = function(){
        this.callback();
    };

}

manager = new SectionManager();
manager.run();

It was also necessary to rewrite the $jScroller.scroll function in order to include an asynchronous callback upon reaching the end: This triggers the manager's callback function, transitioning the scrolling to the subsequent section.

Edit: For further details, please refer to the jsfiddle link

Answer №2

If you're looking to add some dynamic scrolling effects to your website, you might want to check out Scrollorama. This tool allows you to easily pin and unpin elements as users scroll through the page, creating a unique interactive experience for visitors.

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

Updating the variables of HTML components using JavaScript after making an AJAX request

I am using ajax to fetch a list of user data. But after this ajax call, I need to display the data in an HTML structure like a datasheet for each user. My question is how can I store the HTML code in a functional and elegant way to maintain readability and ...

jQuery Datatables Ajax request breaks after initial execution

In my code, I have implemented a datatable as shown below: var dt = $("#reservations").DataTable( { columns: [ { data: "ReservationStart", render: function (data) { return $.format.date(data, "d MMM, yyyy h:mm a"); } }, { data: "Covers" }, { data: "id", re ...

Design a search page with expandable fields for a user-friendly experience

Initially, my search page displays 12 fields. I would like to add a link labeled "MORE" that will reveal an additional 10 fields, including the original ones. If the user clicks on "HIDE," these extra 10 fields will disappear as well. ...

Transmit information to Vue.js component

I am encountering an issue while attempting to transfer data from one component to another. Can someone provide assistance? Below is the code snippet: <template> <div class="q-pa-md" style="max-width: 900px"> <div v-if="fields.length" ...

Monitor the x and y positions for platformer game interactions using only JavaScript and jQuery

I am currently working on a 2D platformer game as part of my college project alongside my friends. We are using jQuery and pure JS for development. So far, we have been able to move the character left and right using jQuery's animate function, and ena ...

Having trouble syncing a controller with AngularJS

Despite numerous attempts, I am still struggling to make a single controller function properly. Lately, I've been working on Angular projects and no matter what I do, my controllers just won't cooperate. In my latest project, everything is withi ...

What is the best way to verify if an Android permission request has been successfully granted or denied

I've been working on my RN application and encountered the following code snippet. import { PermissionsAndroid } from 'react-native'; export default new Promise(() => { return PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS ...

Show Text When Clicking Within Separate DIVs

I have a set of three divs. One contains a Twitter icon, another holds a LinkedIn icon, and the last one is designated for displaying text upon clicking. My goal is to click on the Twitter icon and have corresponding text appear in the third div. Then, if ...

Issue with event delegation when using if-else conditions is not being resolved

I have set up an event listener on an HTML container, and when the user clicks on the play again button, the code inside the 'if' statement should be executed. However, nothing happens when clicking on the play again button and no logs are output ...

JavaScript - Problem transferring an object between two different JavaScript files

Welcome! I am just starting to learn JavaScript. Excuse me if I don't know all the technical terms yet. Scenario Currently, my project consists of three main files: index.html main.js sites.js index.html <body> <h ...

How can I ensure that my function only returns a value once the ajax call has finished?

Using mootools, I have a function that triggers an ajax script to retrieve a value. However, the function seems to return before the AJAX call is completed! What could be causing this issue... function getCredits() { var loadGlobalTab = new Request.J ...

Passing a null value to the server through jQuery AJAX is not possible. Instead, the server receives the string "null" as the value

Recently, I've been working on updating a javascript/php/ajax application to incorporate jQuery so that it can function smoothly across all browsers, not just Firefox. However, I've hit a snag when trying to pass true, false, and null values usi ...

Utilizing Regex to eliminate consecutive duplicates in a string separated by spaces

My current challenge involves removing only sequential duplicates from a string. For example, in the string "1 2 3 3 2 1", I want to remove one of the consecutive 3's so it becomes "1 2 3 2 1". I thought I had the solution figured out, but when I test ...

How can I retrieve the value of a specific <span> element by referencing the class of another <span> within

I have come across the following HTML: <div class="calculator-section"> <p> <span class="x"></span> <span class="amount">30</span> </p> <p> <span class="y"></span ...

Different ways to trigger code behind method with onclick excluding asp:button OnClick

I am working with asp.net and I have a form that already uses runat="server". I have added another form to the page and I need to run a method in the code behind on an onclick event. Since I already have one form on the page, I cannot use an asp:button wi ...

Working efficiently with query selectors in React using useRef

I have created a typewriting effect function and now I am trying to display the code associated with this effect within a specific div element (typingRef). Currently, I am using typingRef.current = letter, but I am wondering if this is equivalent to docu ...

``Passing a variable to a Jquery function - A step-by-step guide

As a beginner in JQuery, I am exploring various functions available online, one of which enables the display of a tooltip when hovering over an HTML element. This is the specific function: <script> $(document).ready(function() { $('#my-tool ...

Creating a unique custom bullet style by utilizing the ::before pseudo-element that results in a noticeable gap between the first two

Explore this Code Here is the issue at hand: https://i.sstatic.net/Fp6u2.png My HTML code looks like this: <ol class="steps"> <li> Select elements are displaying correctly <br> <select> </ ...

jQuery Mobile hyperlinks are malfunctioning despite having identical coding

I'm facing an issue with my jquery mobile site where some links are functioning correctly while others are not. The links for the top logo, "Bundle", and "Legal Disclaimers" don't seem to work even though they are all coded the same. If anyone ca ...

What methods can I use to accomplish the transformation of superimposed images?

Struggling with transforming a content box on my webpage. I have a div containing three overlapping images positioned using Grid, and I want to scale one of them to fill the entire div when scrolled over. While I managed to achieve this effect, I'm un ...