Is there a way to boost the slides limit and make it dynamic? As of now, it's restricted to just

I am looking to achieve the same fadeIn and fadeOut effect as demonstrated in the example below:

However, the issue I'm facing is that this example was designed for only 3 slides and I need more than 3 slides or the ability for it to dynamically increase.

How can I modify the script to automatically accommodate the maximum amount of slides? If I generate the slideshow dynamically within a CMS, for instance, it's impossible to predict the exact number of slides beforehand. Hence, I don't want to manually update the *.js file every time at these specific parts :/

if (this.Last < 1) { 
this.Last = 3;
} 

if ($$.Slideshow.Counter > 3) 
{ 
$$.Slideshow.Counter = 1; # 
} 

It would be greatly appreciated if someone could assist me (and probably many others) with this issue :)

Below is the JavaScript used in this example:

var $$ = $.fn;

$$.extend({
  SplitID : function()
  {
    return this.attr('id').split('-').pop();
  },

  Slideshow : {
    Ready : function()
    {
      $('div.tmpSlideshowControl')
        .hover(
          function() {
            $(this).addClass('tmpSlideshowControlOn');
          },
          function() {
            $(this).removeClass('tmpSlideshowControlOn');
          }
        )
        .click(
          function() {
            $('div.tmpSlide').hide();
            $('div.tmpSlideshowControl').removeClass('tmpSlideshowControlActive');

            $('div#tmpSlide-' + $(this).SplitID()).show()
            $(this).addClass('tmpSlideshowControlActive');
          }
        );

      this.Counter = 1;

      this.Transition();
    },

    Transition : function()
    {
      if (this.Interrupted) {
        return;
      }

      this.Last = this.Counter - 1;

      if (this.Last < 1) {
        this.Last = 3;
      }

      $('div#tmpSlide-' + this.Last).fadeOut(
        'slow',
        function() {
          $('div#tmpSlideshowControl-' + $$.Slideshow.Last).removeClass('tmpSlideshowControlActive');
          $('div#tmpSlideshowControl-' + $$.Slideshow.Counter).addClass('tmpSlideshowControlActive');
          $('div#tmpSlide-' + $$.Slideshow.Counter).fadeIn('slow');

          $$.Slideshow.Counter++;

          if ($$.Slideshow.Counter > 3) {
            $$.Slideshow.Counter = 1;
          }

          setTimeout('$$.Slideshow.Transition();', 5000);
        }
      );
    }
  }
});

$(document).ready(
  function() {
    $$.Slideshow.Ready();
  }
);

I have also conducted some research and encountered another interesting issue:

Upon increasing the Last value from 3 to 5, there seems to be a problem with the navigation controls - When you are on slide 4 and click on slide 2, the navigation will jump back to the previous track, meaning it will move to slide 5 instead of 3.

If anyone could provide assistance with this, it would be highly appreciated.

Answer №1

To dynamically determine the number of slides, it is recommended to utilize jQuery to retrieve this information using the .length property:

// Fetch total slide count
var totalSlides = $("#carouselContainer > .slide").length;

if (this.Index < 1) { 
    this.Index = totalSlides;
} 

if ($$.Carousel.Count > totalSlides) { 
    $$.Carousel.Count = 1;
}

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

Getting rid of the 'label' decorator in Zend 2 forms

Here is a basic Radio element example: $form->add([ 'name' => 'account_type', 'type' => 'Zend\Form\Element\Radio', 'options' => [ ...

PHP seems to be malfunctioning and causing issues with the session

I'm facing an issue with my PHP session. The login page is functioning correctly, but once I redirect to the home page, my login details are not being displayed. An error is being thrown: Notice : Undefined index: username in C:\xampp\htdocs ...

The functionality of Angular's ng-change or ng-click for select elements is not functioning properly

Exploring the concept of ng-change with checkboxes in this example. Check out the live example here Attempting to convert checkboxes into a selection but encountering some challenges. Here is the code snippet: <select> <option ng-model="confi ...

Issue with socket.io and crypto.js communication

My previous Socket.IO example was quite simple, but it stopped working after I updated to Socket.IO 0.6.1 (installed with npm) and node.JS 0.5.0-pre (without ssl). Within transports/websocket.js:128:22, there is an attempt to use crypto.js:101 [return new ...

Identifying the difference between var and JSON.stringify

Take a look at this code snippet: var data = JSON.stringify({ id: _id, ReplyId: _idComment }) openDialog(_url, data, $('#div-modal1')); function openDialog(url, Id, div) { //How can we identify if variable Id is of type JSON.stringi ...

The HTML element seems to be missing its height parameter

My element doesn't have a set height, but it's populated with images causing the Anchor around the images to be unclickable unless I assign a fixed height to .portfolio. Any ideas on how to resolve this? HTML Snippet : <h1 class="text-c ...

Utilizing JQuery in Wordpress to manipulate content within dynamically generated AJAX divs

Currently, I am integrating a Questionary plugin into my WordPress website and populating content through Ajax. One of the questions in the questionnaire prompts users about the time. To style the timepicker using custom JavaScript and CSS, all I need to ...

Is it possible for the handler to still be executed even after canceling an AJAX request?

After exploring the discussion on whether JavaScript is truly single-threaded, it is evident that despite JavaScript being primarily single-threaded, there are exceptions to keep in mind. I am curious about the predictability of the following pseudo-code ...

I'm experiencing difficulty accessing the correct identification number for my questions on the website

Hi, I'm currently developing a website using Meteor where users can post questions and receive answers. I want to implement a feature that allows users to delete their own questions. When I try to directly pull the ID of the question and delete it, it ...

Unlock the full potential of Vuejs by implementing HTML5 validation checks for input fields

How can I incorporate html5 form.checkValidity() with a form that includes custom components in vuejs 2? Validation works seamlessly with standard html5 inputs: <form name="myform" ref="formref"> <input type="text" ...

Challenges in accessing a specific button when faced with multiple buttons sharing the same class in Protractor

Code in HTML <button type="button" class="btn btn-default btn-sm pull-right" ng-click="move(1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-right"></i></button> I'm looking for a solution in Angular Protractor that wi ...

Custom Internet Explorer Stylesheet

My webpage (specifically a game) is behaving differently on Internet Explorer compared to other browsers, despite my efforts to fix it through online searches. <!--[if IE ]> <link rel="stylesheet" type"text/css" href="iestyle.css"> <![endif ...

The timer is malfunctioning

I am new to JavaScript and looking to create a simple countdown. I came across this script: http://codepen.io/scottobrien/pen/Fvawk However, when I try to customize it with my own settings, nothing seems to happen. Thank you for any assistance! Below is ...

Encountering a 404 error for core.js and browser.js while loading an Angular 2 app through system.src.js

I am new to Angular2 and have followed the Angular2 quickstart and tutorial to get started. Just to provide some context, when a user clicks on a link in the top navigation bar of my webapp, it triggers a server side request. The resulting page returned t ...

String ES6 syntax immediately after function

return pool.query`select * from mytable where id = ${value}` How can the code snippet above be rewritten in full JavaScript? I attempted to use: return pool.query(`select * from mytable where id = $(value)`) but it seems like there is a difference. Th ...

What is the correct RegEx pattern I should use to properly match the provided test case without including the ending period?

Regular Expression: /@([\S]*?(?=\s)(?!\. ))/g Given String: 'this string has @var.thing.me two strings to be @var. replaced'.replace(/@([\S]*?(?=\s)(?!\. ))/g,function(){return '7';}) Expected Result: ...

The absence of a function definition within a controller is a common issue in AngularJS

I have been attempting to run a function once a video finishes playing. The function is located within an angular controller, but I am encountering an error message that reads: ReferenceError: postVendor is not defined Below is the JavaScript code where ...

Click to solve the equation

I want to build a basic HTML page with three input variables (A,B,C). After the user inputs these values, they will click "calculate", and JavaScript will execute the following equations: ((A + B)/2) * 3 = X and (C * 2) = Y The results will be displaye ...

Unexpected token encountered when using JSON.parse()

I'm encountering an issue where trying to use JSON.parse() on a specific string is resulting in an unexpected token error. It seems to be having trouble with the 'maker' part of the data. Any insight on this issue would be greatly appreciate ...

Cease the countdown once it reaches the specified date

I am currently running a Christmas countdown on my website, but I'm struggling to make it stop once the exact date is reached. function countdown(){ var now = new Date(); var eventDate = new Date(2016, 11, 25); var currentTime = now.getTime(); var ...