What are the common reasons for jQuery Image Slider malfunctioning?

After following a tutorial on Youtube (https://www.youtube.com/watch?v=KkzVFB3Ba_o) about creating a JQuery image gallery, I realized that my implementation is not working at all. Despite carefully reviewing my code and fixing any errors I could find, the gallery still fails to function. What am I missing?

Here's a snippet of my HTML:

<div id="slider">
  <ul class="slides">
    <li class="slide"><img src="images/1.jpg"></li>
    <li class="slide"><img src="images/2.jpg"></li>
    <li class="slide"><img src="images/3.jpg"></li>
    <li class="slide"><img src="images/4.jpg"></li>
    <li class="slide"><img src="images/5.jpg"></li>
    <li class="slide"><img src="images/6.jpg"></li>
  </ul>
</div>

My CSS:

#slider
{
    width: 720px;
    height: 400px;
    overflow: hidden;
}

#slider.slides
{
    display: block;
    width: 6000px;
    height: 400px;
    margin: 0;
    padding: 0;
}

#slider.slide
{
    float: left;
    list-style-type: none;
    width: 720px;
    height: 400px;
}

Javascript/jQuery section:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">

    $(function() {

    var $slider=$('#slider');
    var $slideContainer=$slider.find('.slides')
    var $slides=$slideContainer.find('.slide');
    var width=720;
    var animationSpeed=1000;
    var pause = 3000;
    var CurrentSlide=1;
    var interval;

     function startSlider()
     {


        interval= setInterval(function(){
            $slider.animate({'margin-left': '-='+width},animationSpeed,function()
                CurrentSlide++;
                if (CurrentSlide===$slides.length){
                    CurrentSlide=1;
                    $slideContainer.css('margin-left',0); 
                }
                });
        },pause);
    }

    function pauseSlider()
    {
        clearInterval(interval);
    }

       $slider.on('mouseenter',pauseSlider).on('mouseleave',startSlider);
       startSlider();

    });



</script>

Mentioned source folder for my project: https://drive.google.com/open?id=1M3kvUAWlCRqiZIWLLmTH_60qo0gsxzgT

Answer №1

something seems to be absent

<ul class="carousel">

Answer №2

Don't forget to include curly braces after the function declaration

  $slider.animate({'margin-left': '-='+width},animationSpeed,function()

The correct syntax is:

  $slider.animate({'margin-left': '-='+width},animationSpeed,function(){

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

The date-fns parse function will retrieve the value from the previous day

When attempting to parse a date using the date-fns library, I am encountering an issue where the resulting date is one day prior. How can this be resolved in order to obtain the correct result? start = '2021-08-16' const parseStart = parse(start, ...

Having trouble deleting the value and deselecting the checkbox item?

Feeling a bit confused about a coding issue I'm facing. The problem lies in the categories listed in my database, which I fetched and used to create a post. Now, I'm attempting to edit that post. The categories are in checkbox format, where check ...

The issue arises when Node.js fails to identify the input fields that were dynamically inserted into the form

I came across a question similar to mine, but I found it challenging to apply the solution to node js. In my project, users can add items to a cart by clicking on them, which are then dynamically added to a form using jquery. However, upon submission, only ...

In React Native, you can pass native component properties as props, while also defining custom ones using a TypeScript interface

I am working on a component called AppText where I need to utilize a Props interface and also be able to accept additional props that can be spread using the spread operator. However, I encountered this error: Type '{ children: string; accessible: tru ...

Enable the use of multiple decimal separators in a ReactJS application

I am currently developing a small project that involves using a POST request, which requires multiple fields with 2 float values. My backend system expects the decimal separator to be a ".", but my target audience is primarily French and they ar ...

Tips for utilizing mysql_connect(...) on a web hosting platform

Recently, I signed up for a web hosting service and have just started learning PHP and MySQL. I came across this video tutorial https://www.youtube.com/watch?v=gvGb5Z0yMFY which demonstrates how to add a row to a table. In my MySQL database, I have a table ...

Debugging TypeScript on a Linux environment

Approximately one year ago, there was a discussion regarding this. I am curious to know the current situation in terms of coding and debugging TypeScript on Linux. The Atom TypeScript plugin appears promising, but I have not come across any information ab ...

scrape particular data from a table using scrapy

Currently, I am utilizing scrapy to extract content from a website specifically located within a particular <td> tag. The guide provided demonstrates downloading all the information, however, I only require the data from one individual <td>. As ...

Struggling to update a Knockout observable array

I'm attempting to send some data to a Knockout observable array. Despite receiving data from my AJAX call without any errors during script execution, I find that the userNames array remains empty when accessed. What could be causing this issue? UserH ...

Angular Bootstrap notifications will stay open indefinitely and will not automatically dismiss after a certain period

I need help with adding alerts using Angular Bootstrap that should dismiss themselves after a certain timeout. However, the alerts are not dismissing on their own. Here's the code snippet: angular.module('ui.services').service('AlertSe ...

What is the most effective approach for annotating TypeScript abstract classes that are dynamically loaded?

I am in the process of developing a library that allows for the integration of external implementations, and I am exploring the optimal approach to defining types for these implementations. Illustration abstract class Creature { public abstract makeN ...

Automatic audio playback with jQuery

I am attempting to automatically play audio based on a condition when I receive an ajax response. Even though I get response.code == 1 from my ajax call, the audio does not start playing. <audio id="myAudio" > <source src="{{ass ...

Is there a way to calculate the total of three input values and display it within a span using either JavaScript or jQuery?

I have a unique challenge where I need to only deal with positive values as input. var input = $('[name="1"],[name="2"],[name="3"]'), input1 = $('[name="1"]'), input2 = $('[name="2"]'), input3 = $('[name=" ...

transition from jQuery to Zepto

I have been utilizing multiple jQuery plugins in my codebase... Recently, I decided to switch over to Zepto, but encountered an issue Uncaught TypeError: Object function (a,b){return A.init(a,b)} has no method 'data' when checking the console ...

Ways to enhance widget titles with borders on Blogger

As a Blogger user, I am looking for guidance on how to add a border around the title of each widget/gadget. When I place widgets such as About Me, Follow Us, etc., in my sidebar, I want them to have borders like in this image. While I know how to customize ...

Updating the value within a nested array in a ReactJS application

Check out the working code here: https://codesandbox.io/s/broken-https-2i454?file=/src/App.js I'm currently using Material UI within my reactjs project and facing an issue updating the value entered in a textfield of a table using the onChange functi ...

Issues with refreshing the content in form fields

I am encountering issues with reloading fields, especially the datepicker in a form. The website is live at , and when I attempt to search using the search form, it works fine the first time. However, if I press the reset button before searching again, th ...

Tips for bringing in pictures from outside directories in react

I am new to React and trying to import an image from a location outside of the project's root folder. I understand that I can store images in the public folder and easily import them, but I specifically want to import them from directories outside of ...

Stop specific characters from being input into a text field

My goal is to restrict the characters allowed in a text box to the following: A to Z in both upper and lower case, Ñ and ñ, and space. I have a function that runs onkeyup: FieldOnKeyUp(el) { !(/^[A-zÑñ-\s]*$/i).test(el.value)?el.value = el.value ...

Creating a mobile-friendly split column layout with Bootstrap 5

I have a similar question to the one posed in this thread How to split Bootstrap column in mobile mode, but I am working with Bootstrap 5 and the previous solution using float: right no longer works due to flexbox. On desktop, I have two columns and I wan ...