Problem with using Jquery DIY slider for multiple purposes

There seems to be an issue with the DIY Slider that I'm using. Whenever I attempt to use this slider more than once on a single page, the second one fails to function.

I have exhausted all possible solutions that come to mind.

$(".slider").diyslider({
    width: "400px", // set the width of the slider
    height: "200px", // define the height of the slider
    display: 1, // specify number of slides to display at a time
    loop: false // turn off slide looping 
}); // these are the essential settings!

// utilize buttons for slide navigation
$("#go-left")bind("click", function(){
    // Move back to the previous slide
    $(".slider").diyslider("move", "back");
});
$("#go-right").bind("click", function(){
    // Move forward to next slide
    $(".slider").diyslider("move", "forth");
});

http://jsfiddle.net/bj4yZ/155/ - Visit this link for a demonstration of the working "not working" scenario.

Answer №1

To ensure proper functionality, remember to update the id's of each element individually. Failure to do so may result in all events being linked to the first slider.

Check out this example on JSFiddle for reference

<button id="go-left">&laquo;</button> <button id="go-right">&raquo;</button>

<div class="slider"><!-- The slider -->
    <div><!-- A mandatory div used by the slider -->
        <!-- Each div below is considered a slide -->
        <div class="a">Div #1</div>
        <div class="b">Div #2</div>
        <div class="c">Div #3</div>
        <div class="d">Div #4</div>
        <div class="e">Div #5</div>
    </div>
</div>

<button id="go-left2">&laquo;</button> <button id="go-right2">&raquo;</button>

<div class="slider2"><!-- The second slider -->
    <div><!-- A mandatory div utilized by the second slider -->
        <!-- Each div below represents a different slide -->
        <div class="a">Div #1</div>
        <div class="b">Div #2</div>
        <div class="c">Div #3</div>
        <div class="d">Div #4</div>
        <div class="e">Div #5</div>
    </div>
</div>

Below is the JavaScript code:

$(".slider").diyslider({
    width: "400px", // set the slider width
    height: "200px", // define the slider height
    display: 3, // specify the number of slides to show at once
    loop: false // disable slide looping
}); // minimal setup required!

// use buttons for slide navigation
$("#go-left").bind("click", function(){
    // Move to previous slide
    $(".slider").diyslider("move", "back");
});
$("#go-right").bind("click", function(){
    // Move to next slide
    $(".slider").diyslider("move", "forth");
});



$(".slider2").diyslider({
    width: "400px", // set the slider width
    height: "200px", // define the slider height
    display: 3, // specify the number of slides to show at once
    loop: false // disable slide looping
}); // minimal setup required!

// use buttons for slide navigation
$("#go-left2").bind("click", function(){
    // Move to previous slide
    $(".slider2").diyslider("move", "back");
});
$("#go-right2").bind("click", function(){
    // Move to next slide
    $(".slider2").diyslider("move", "forth");
});

Hopefully this explanation is helpful!

Answer №2

Using an each() function on the slider calls can help effectively separate elements.

Check out this live demo

Unfortunately, Diyslider lacks the necessary features to accomplish this task independently.

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

Tips for importing font files from the node_module directory (specifically otf files)

We cannot seem to retrieve the fonts file from the node module and are encountering this error message. Can't find 'assets/fonts/roman.woff2' in 'C:\Projects\GIT2\newbusinessapp\projects\newbusinessapp\src ...

Could an element's loading be postponed on the initial page a user lands on?

One of my clients has requested a live chat system to be added to their website. I am fully capable of implementing it, and it is included through a script tag. Additionally, they have asked for a slight delay before the chat system loads in. My initial t ...

.value not being grabbed from options of selected index

I have a form that includes a select field with the id of "to". My goal is to retrieve the selected value within a JavaScript function. Interestingly, the first time I execute this function, it fails to capture the selected value. However, upon running t ...

Selecting Child Elements in CSS

Suppose I have the below HTML structure: <div id="div1"> .... <span class="innercontents">...</span> .... </div> Is it possible to target only the child elements of a specific parent ID? For example, could I use this CSS rule? # ...

Experiencing Setbacks while Implementing AJAX in a PHP Object Orient

I'm currently attempting to create an object-oriented programming (OOP) login system using Ajax. However, I am encountering issues with starting the session or being redirected to the "Directivo.php" page. When I run the code, there is no output displ ...

javascript guide to dynamically update the glyphicon based on value changes

I am attempting to implement an optimal level feature where a glyphicon arrow-up will be displayed if a value falls within the optimum range, and it will switch to a glyphicon arrow-down if the value is lower. <div class="card-body" ng-repeat="item i ...

Ensuring the Accuracy of User Input within Bootstrap's jQuery Modal Popup

What is the best way to validate an input control within a Bootstrap jQuery modal dialog? Check out some examples of modal dialogs in this link http://getbootstrap.com/javascript/#modals The Bootstrap Modal examples typically contain this type of Input: ...

How can I invoke a PHP script using AJAX?

I am currently working on implementing a feature that involves multiple tables where users can move table rows between the tables. I want to use ajax to call a php script that will update the database with the new values, specifically assigning a new paren ...

Switching the background image upon hover while incorporating a subtle fade transition in HTML and CSS

Is there a way to set two background images on a div and have them change when hovering with a fade effect? Similar to the example shown. .kid { max-width:50%; position:relative; } .kid img { display:block; opacity:1; height: auto; transition:.6s ease; ...

Tips for refreshing jQuery to ensure it functions smoothly for subsequent tasks

I am facing an issue with running a second process under JQuery, as shown in the code snippet below: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <script type=" ...

What could be the reason for my new course not being recognized?

Looking to modify the behavior of a button where, when clicked, it hides a specific div element, changes its text display, and toggles between classes using addClass/removeClass for subsequent click events. Unfortunately, the intended functionality is not ...

Prevent a submit button from submitting a form using jQuery

I am working on developing a password manager similar to a chrome extension. The goal is to detect the username and password fields when a user tries to log in to a website, such as Facebook, and then prompt the user if they would like to save these creden ...

The functionality of the AJAX Script is failing to load properly on mobile devices

Currently, I am undertaking a project that involves ESP32 Arduino programming to create a webpage where users can interact with buttons to activate relays. Additionally, I have implemented a slider using a short script. This project is inspired by the ESP3 ...

Inconsistent expansion panel widths observed in Chrome when using React material-ui

I've encountered an issue in Chrome where the width adjusts to fit its content instead of taking up the full width of the container. However, this problem does not occur on Firefox. https://i.stack.imgur.com/HyWGU.png When I click on the expand icon ...

Tips on ensuring a jQuery script continues to run even after the window location has been changed

Is there a way to wait for the page to reload from HTTP to HTTPS using document.location before continuing the jQuery script? The script seems to be executing before the new location is fully loaded. How can I ensure that the script waits for the reload ...

Is there a way to identify all the elements that have properties like border and border-radius applied to them?

When looking for elements with certain properties, you can use queries like this; $$('*[title]') For example, if you want to find elements with a border or border-radius applied, standard queries may not work. $$('*[border-width]') // ...

Utilizing Ajax Blob URL for Audio Streaming

My goal is to retrieve audio data using an Ajax request and load it into an audio element. However, I'm running into an issue where the player does not seem to work properly. The play button remains disabled as if nothing has been loaded. Below is a s ...

Achieving proper HTML element order?

Here is the HTML page I am working with: Click here to view the code on jsfiddle <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Extended UI</title> <style type="text/css"> .header{ padding-rig ...

Retrieve the date for the chosen time slot by utilizing the fullCalendar feature

I've been experiencing issues with a piece of code that is supposed to retrieve the date corresponding to a user-selected slot. Here's what I've tried so far: $('.fc-agenda-axis.fc-widget-header').on('mousedown', functio ...

Utilizing a jQuery datepicker to dynamically populate future dates from JSON data

Looking for a jQuery datepicker that can read JSON data... I have a list of upcoming dates for each month in my JSON file that I want the datepicker to disable and highlight with a specific color. ...