The slider is malfunctioning and not functioning properly in JSFiddle

As a beginner in the world of coding, I decided to start my journey with Codecademy. Everything seemed to be going smoothly as I created a carousel image slider using JQuery. However, when I tried implementing the same code on jsfiddle, the slider became static and stuck on one image.

This is the JQuery code that I used:

$(document).ready(function() {
  var $slider = $('.slider'); 
  var $slide = 'img';
  var $transition_time = 2500;
  var $time_between_slides = 4000; 

  function slides(){
    return $slider.find($slide);
  }

  slides().fadeOut();

  // set active classes
  slides().first().addClass('active');
  slides().first().fadeIn($transition_time);

  // auto scroll 
  $interval = setInterval(
    function(){
      var $i = $slider.find($slide + '.active').index();

      slides().eq($i).removeClass('active');
      slides().eq($i).fadeOut($transition_time);

      if (slides().length == $i + 1) $i = -1; // loop to start

      slides().eq($i + 1).fadeIn($transition_time);
      slides().eq($i + 1).addClass('active');
    }
      ,$transition_time +  $time_between_slides 
  );
});

The images for the slider are stored as follows:

<div id="jumbotron"> 
 <div class="slider">
    <img class="img" src="http://photos.travellerspoint.com/203325/Peru_239.jpg" width="100%">
    <img class="img" src="https://c2.staticflickr.com/4/3367/5734521147_ab8fa45d8a.jpg" width="100%">
    <img class="img" src="http://cdn.c.photoshelter.com/img-get/I0000aT96V0jJZX4/s/650/650/Alpaca-Wool-Factory-El-Alto-Bolivia-17.jpg" width="100%"> 
    <img class="img" src="https://kitaliana.files.wordpress.com/2011/09/rug_cusco1.jpg" width="100%">
</div>
</div>

Having encountered this issue for the first time, I was at a loss on where to even begin troubleshooting. It's puzzling how the code worked perfectly in one environment but failed in another, despite being identical...

Answer №1

Consider trying this:

let $animation_duration = 3500;

Rather than:

let $animation_duration = 35_00;

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

Unable to get CSS to function properly on website

I am having trouble getting my text to format properly on my web page. I have defined rules in my style sheet to center an object on the screen, but it's not working as expected. Here is the code for my web page: body { text-align: center; } h1 { ...

Finding an element's id within a click event inside an iframe

<iframe id="myiframe" src="doc.html"> <button id="btn1"></button><!-- how do I retrieve this id? --> </iframe> $('#myiframe').on('click', function () { alert(this.id); }); I am trying to make it ...

Functions perfectly in jsFiddle, however does not function as intended on my personal website

I am experiencing a strange issue with the jQuery code on my website. Surprisingly, the code works perfectly fine on jsFiddle but not when I run it locally. Both instances have the exact same code as I simply copied and pasted it. Can anyone provide insi ...

I am having trouble getting the pagination to function properly on my custom materialize projects

I am experiencing issues with the list of sub-pages on the official demo sites: Materialized Materialize(css) The navigation bar does not update the active page number or content when clicked. Both websites are using materialize css. If you click ...

Unable to apply programatically loaded attributes to the rangeslider.js plugin

I'm having trouble with my graph editor that uses the rangeslider.js plugin. The bars are not updating properly most of the time, and sometimes they don't work at all. I have a demo available here and a simplified version on Fiddle. Strangely, so ...

only displaying the months on the calendar widget

There is a specific condition in my code where, depending on the value entered, the jQueryUI datepicker will either display days or months. function setdate(q){ var d=new Date(); if (q==1){ var type={ ...

Is it possible to arrange buttons next to each other?

Here is the code for a specific page: HTML: <div class=main> <div class=bttn> <button>abcdef</div> <div class=content> <a href=#!>jksg</a> <a href=#!>jksg</a> & ...

The Angular Material Nav Sidebar is specifically designed to appear only when resizing the screen to

I am currently following a tutorial on setting up Angular Material Sidenav with a toolbar from this video (https://www.youtube.com/watch?v=Q6qhzG7mObU). However, I am encountering an issue where the layout only takes effect after resizing the page. I am no ...

Utilizing the Bootstrap grid system to dynamically adjust column width based on specific conditions

When working with HTML and bootstrap (3.7) CSS, I often come across this issue: <div class="row"> <div class="col-xs-6">Stretch ME!</div> <div class="col-xs-6">Conditional</div> </div> Sometimes the "Conditional" d ...

Guide on automatically extracting table rows and generating an Excel spreadsheet

I am currently working on a script that dynamically adds the first row (TH) to a table and then exports it to an Excel sheet. However, I am facing an issue where instead of appending each row, the script keeps stacking on top of the next table row. Below ...

Exploring the World of jQuery Caching and Navigating Through Objects

I'm interested in learning more about jQuery caching and how it can enhance performance. Can you explain how to properly utilize this technique? From what I understand, when using a jQuery selector, you're essentially searching the DOM to create ...

Conditionals are always evaluated as true

After writing this post function in my jQuery plugin, I encountered a peculiar issue. I have a doubt about the condition statement in this jQuery code. Can you confirm if it is correct? if(info = "enabled"){ $("#mod"+mod_id+" > img.status").attr(" ...

Achieving a Photo Grid Layout with CSS

Looking for help with my CSS photogrid - it's close to what I want, but not quite there. Here's the layout I'm aiming for: 1 | 2 | 3 4 | 5 | 6 But currently, it displays like this: 1 | 3 | 5 2 | 4 | 6 I've tried tweaking the CSS but ...

Switching between slides by utilizing anchor tags or buttons located in separate div containers

On my webpage, I have a Bootstrap carousel and I'm looking to switch between slides by using anchor tags or buttons located in separate div elements. Can anyone provide guidance on how to achieve this? ...

Issues arise when attempting to smoothly scroll to an anchor point in a webpage

While working on my website, I have encountered a challenge. The issue arises when dealing with multiple div items. Upon scrolling slightly, the entire page focuses on the div with a height of 100vh, which works perfectly fine. However, my attempts to ...

Enhance your image viewing experience with a React component that smoothly zooms in on images without distorting their dimensions, all with

After searching extensively for a solution, I have been unable to find one that works. My current setup involves using React with Bootstrap. I am in need of a stateless functional component that can take an image path as input and return an img element. Th ...

Enhance your textbox with more detailed descriptions than just displaying NaN

I am working on a form that includes select boxes. If a user selects an option from "Convert From" and another option from "Convert To" but does not enter a number in the input field, instead of displaying NaN in the result text box, I would like to show ...

``There seems to be an issue with JQuery.Ajax not properly displaying on Samsung Smart

I attempted to use JQuery.Ajax to interact with my webservice Below is the code snippet: Main.onLoad = function() { // Enable key event processing this.enableKeys(); widgetAPI.sendReadyEvent(); //$("#h2Test").html("Change On Text"); ...

Outlook fails to recognize table cell widths when there is an image present

Although this question has been asked previously, the solutions provided did not solve my issue. I am trying to set the width of the <td> element to 70%, but when I insert an image it is affecting the widths of received emails in Outlook (I use MS O ...

Utilizing regular expressions to find the attribute name within nested array brackets by matching the index number

Can someone assist me with RegEx? I am trying to extract only the index number found within brackets [1] in a string that looks like this: text[alphanumeric][index][text]. Please see the example attribute name below. name="lorem[ipsum_dolor_set-amet-34][1 ...