Four images are loaded sequentially in a single scroll in the sequencer

I am facing an issue with this plugin's jQuery code. Currently, the code allows only one image to move in one scroll. However, I need to make four images move one by one in a single scroll sequence. Additionally, I would like to set a specific time interval for each image transition. Can anyone assist me in solving this problem?

Check out the Plugin Demo here

(function($) {

  $.fn.sequencer = function(options, cb) {

    var self = this,
        paths = [],
        load = 0,
        sectionHeight,
        windowHeight,
        currentScroll,
        percentageScroll,
        index;

    if(options.path.substr(-1) === "/") {
      options.path = options.path.substr(0, options.path.length - 1)
    }

    for (var i = 0; i <= options.count; i++) {
      paths.push(options.path + "/" + i + "." + options.ext);
    }

    $("<div class='jquery-sequencer-preload'></div>").appendTo("body").css("display", "none");

    $(paths).each(function() {
      $("<img>").attr("src", this).load(function() {
        $(this).appendTo("div.jquery-sequencer-preload");
        load++;
        if (load === paths.length) {
          cb();
        }
      });
    });

    $(window).scroll(function() {
      sectionHeight = $(self).height();
      windowHeight = $(this).height();
      currentScroll = $(this).scrollTop();
      percentageScroll = 100 * currentScroll / (sectionHeight - windowHeight);
      index = Math.round(percentageScroll / 100 * options.count);
      if(index < options.count) {
        $("img.sequencer").attr("src", paths[index]);
      }
    });

    return this;

  };

}(jQuery));

Answer №1

If you're looking to update an image periodically, the setInterval() function is what you need.

You can easily create a function to handle image changes and then pass that function as an argument to setInterval().

To achieve this, add something like the following at the conclusion of your script:

setInterval(changeImage, 60000);
//calls the changeImage() function every minute

For more information on how setInterval() works, check out this resource.

Hopefully this explanation proves helpful!

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

Having issues with rendering my images on Nuxt framework

In the midst of configuring the routing for my Nuxt project, I've encountered challenges with nesting specific folders to achieve a route structure like this: "/PageAccueil/PricingPage/Checkout123". The issue arises when attempting to place the "Pric ...

What is the best way to dynamically resize row height in Bootstrap?

Currently, I'm delving into Bootstrap and facing a challenge of automatically adjusting row heights under specific conditions: In a container-fluid, there are 3 rows Row1 should accommodate the height of its content Row3 needs to adjust to its conte ...

Filtering with Angular

I have a form that is structured into different sections as shown below: education: {faculty: "", high_school: ""} experience: {experience_1: "", experience_2: "", experience_3: ""} personalInfo: {id: "", type: "", email: "", password: "", password_new: " ...

jQuery AJAX callback fails to trigger

I am encountering an AJAX request in my code: $.ajax({ url : "proxy.php", type : "POST", data : xmlData, contentType : "application/x-www-form-urlencoded", processData : false, success : function(data) { // successful response ...

Using the match.params.id in React: A step-by-step guide

Having some trouble with my React code. I need to display the product name based on its ID, where the product data is fetched from product.js. I am using a router to switch between different products without reloading the page. import product from './ ...

The translation of popups using ngx-translate in Javascript is not functioning properly

When I click on my request, the content "Are you sure?" is not changing to the required language. This issue is located in list.component.html <button type="button" (click)="myrequest(item.Id)">Request View</button> The fu ...

Issue with Material UI Autocomplete: onChange event not firing

When using Material UI's Autocomplete example, I am trying to choose an option using keyboard events: Navigate through options with the Up and Down arrow keys Press ENTER to select the desired option However, the onChange event is not being triggere ...

Issues have been reported with the compatibility of Tailwind CSS when using it with Next.js and Shadow

I've been working on a NextJS project that utilizes shadcn-ui components. However, upon integrating tailwindCSS, I encountered an issue where none of the styling appeared when using classnames. I have double-checked the configurations in components.j ...

Getting the name and value from an object

Just starting out with Javascript and Nodejs, using express and making a call to the following link: localhost:7080/v1/movies/order/notify/insert?breed=Whippet&age=10 After that, I am attempting to extract the property name along with its correspon ...

Leveraging jQuery within a webpack module shared across multiple components, located outside the webpack root directory

When working with multiple layouts that rely on shared typescript files, it is important to ensure these files are accessible across different layouts using webpack. While attempting to include jquery in my ajax.ts, I encountered the following error: ERR ...

What could be causing the unexpected behavior of TypeScript in Visual Studio Code?

VSCode is showing errors, but everything is functioning properly. Here are some of the errors: Type expected. [ { "resource": "/C:/Users/Dell/Desktop/vite-project/src/App.tsx", "owner": "typescript", "code": "1110", "se ...

Exploring a JSON Object with nested properties, crafting changes, and producing a fresh object: A step-by-step guide

I am attempting to manipulate a JSON object with nested properties by replacing numeric values with computed values and returning a new object. The original object looks like this: var obj = { "a0": { "count": 41, "name": "Park", "new": { ...

Stopping a function from executing in React when another function has already provided its data

I am facing a situation where two functions are fetching data from different endpoints in a database. However, one function tends to return data faster than the other at times. // Function One const getDataOne = async => { await fetch('//some-a ...

Transmitting various pieces of information using AJAX

Is it possible to send both "credit_uri" and "address" strings in one AJAX request? Currently, only the second string is being sent. How can I include both in the data of the request? $.ajax({ url: '#{add_cards_path}', type: 'POST&apo ...

Error: Loop Program Encountered Unexpected Token Syntax

Every time I attempt to run this code, a syntax error (unexpected token) appears. As someone who is still learning JavaScript, I am struggling to identify the root cause of this issue. var x = 1; var example = function(){ for(var y = 0; y < ...

sort jquery alphabetical characters

I have created some html and jQuery code that allows me to hide elements based on class name when I click on specific buttons in the filter div. However, I am now looking to add functionality to sort the elements alphabetically by class name when I press ...

Updating the border color on angular-archwizard's steps

I am utilizing angular-archwizard to create circular steps for navigation. When I click on different steps, I can see the circle step border change color (in my case, orange) until I click on the last step. Once I click on the last step, all the other step ...

Store the Ajax JQuery selector within an array for safekeeping

I am completely new to working with Ajax and would appreciate some assistance in storing data from an Ajax request into an array. I have browsed through various solutions on this forum, but so far, I have been unable to resolve my issue. The Ajax respons ...

Struggling to make the height attribute work in Bootstrap 4 alpha

I'm currently in the process of learning Bootstrap, and I've encountered an issue with the height attribute in version 4 (for example: "row h-25") not functioning properly. I attempted to add another CSS rule that sets the height of "container-f ...

Experiencing unexpected outcomes via AJAX requests

Linked to: Query Database with Javascript and PHP This inquiry is connected to my previous question. I made adjustments to the PHP script based on one of the responses I received; however, when attempting to utilize $.getJSON, I encountered difficulties. ...