Controlling multiple bx-sliders with a single pager using only JavaScript

Is there a way to control 3 sliders using the same pager?

I attempted to use the following code but it did not work:

<script language="javascript">
$('.mobile_left_mble,.mobile_right_mble,.text_btn').bxSlider({
  //pagerCustom: '#bx-pager',
  pager:true,
  controls: false,
  touchEnabled : true,
  mode: 'fade',
  easing: 'swing',
  auto :true,
});
$('.mobile_left_mble,.mobile_right_mble').each(function(i){
        alert (i);
        slider_array[i] = $(this).bxSlider({pager:false});
    });
</script>

Answer №1

To start, I would first set up my JS file by initializing three unique elements - 'mobile_left_mble', 'mobile_right_mble', and 'text_btn' - with their own individual BxSlider calls. Each call would be stored in a separate variable for easy access.

var mySlider1;
var mySlider2;
var mySlider3;

jQuery(document).ready(function($){
    mySlider1 = $('.mobile_left_mble').bxSlider({
       pager:false
    });

    mySlider2 = $('.mobile_right_mble').bxSlider({
       pager:false
    });

    mySlider3 = $('.text_btn').bxSlider({
       pager:false
    });
});

Next, in the HTML file, I would create a custom pager for the sliders. Each pager-item would have a specific data attribute to indicate which slide it corresponds to. This way, by clicking on a pager-item, the script can determine the slide index and navigate to the correct slide.

<ul class="one-pager-to-rule-them-all">
    <li><a class="pager-item" data-slide="0">1</a></li>
    <li><a class="pager-item" data-slide="1">2</a></li>
    <li><a class="pager-item" data-slide="2">3</a></li>
    <li><a class="pager-item" data-slide="3">4</a></li>
</ul>

Then, in the JS file, I would create an OnClick event for the pager-items. Using BxSlider's built-in methods, such as 'goToSlide()', the script can easily navigate to the selected slide based on the data attribute of the clicked pager-item.

var toSlide = $(this).attr('data-slide');
mySlider1.goToSlide(toSlide);
mySlider2.goToSlide(toSlide);
mySlider3.goToSlide(toSlide);

By following these steps, all sliders can be controlled using the same custom pager.

For a demonstration, check out this jsfiddle

Does this solution meet your requirements?

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 error message "TypeError: Cannot set property 'href' of undefined" occurred at angular.js line 12520 when trying to set $window.location.href

Has anyone tried using a directive function to redirect when clicking with ng-click? Here is the HTML code: <a ng-click="navbarlinksCtrl.clickedfr()" ng-class="{active: clickedfr()}">FR</a><br> <a ng-click="navbarlinksCtrl.clickeden( ...

Encountering the "Cannot set headers after they are sent to the client" error within an Express.js application

In my recent project, I created a middleware to authenticate users and verify if they are verified or not. Initially, when I access protected routes for the first time, everything works fine and I receive success messages along with verification of the JWT ...

How can I make my opacity change on hover without the need for JavaScript?

I've been attempting to design a book cover that will become fully visible when hovered over, but for some reason it's not working #book_cover { display: block; margin-left: auto; margin-right: auto; width: 25%; height: 71%; ...

Organizing into distinct categories using Angular

I'm a beginner in the world of Angular and programming, seeking guidance on how to learn. I have an HTML page with 5 tabs: "Who," "What," "Where," "When," and "Events." The code snippet below showcases my current setup. Can anyone provide assistance o ...

What is the best way to personalize the collector for each individual?

Currently, I have a bot that is capable of collecting messages and replying if it detects a specific word. However, I am facing an issue where the bot keeps creating new collectors every time someone types the word tekong. As a result, the bot ends up resp ...

Can one manipulate the simulation to make isTrusted=true a reality?

Is there a way to simulate an isTrusted=true in touchStart event triggering? Are there any libraries or workarounds that can make this achievable? When I run the touchStart event programmatically versus physically triggering it, the output differs. Below ...

Creating a unique navigation route in React

My application has a consistent layout for all routes except one, which will be completely different from the rest. The entire application will include a menu, body, footer, etc. However, the one-off route should be standalone without these elements. How ...

The error at line 72 of proxyConsole.js is: TypeError - Unable to access the 'default' property of an undefined object

I am new to using react redux loading bar and redux forms After clicking a button, I want the loading bar to display. The issue arises when I try to load the loading bar, resulting in the following error message: proxyConsole.js:72 TypeError: Cannot read p ...

Ways to determine the count of arrays within a JSON data structure

Displayed below is a JSON object with multiple arrays. The goal is to extract the number and name of each array within this object. Since the object is dynamically generated, the quantity and names of the arrays are unknown. In this example, there are tw ...

How can I correct the code that is running both the if and else statements simultaneously?

In the code snippet below, a comparison is made between a username and password. If both are correct, the user is redirected to another page. However, there seems to be an issue where both the if and else statements are executing. Code: if (isset($_POST[ ...

The @media print rule for Angular 16 in the style.css file is not functioning properly

I'm currently working on an Angular component called ViewTask, which has a template that is rendered inside the app component. The app component also consists of a side nav bar. My goal is to only display the content inside the 'print-section&apo ...

The Bootstrap 4 column is not floating properly to the right as it is leaving a gap on the

My right sidebar is not floating to the right and has space from the right side. You can view it at this link: <div class="col-md-2 col-lg-2 col-sm-2" id="right-sidebar" style="background-color:orange; float: right; right: 0!important; width: 100%;"& ...

Understanding the differences between jquery's addClass method and the .css()

After creating a function to set a background on a click event, I encountered an issue. I attempted two different methods, expecting both to be successful. However, only the .css() version worked while the addClass method failed. Why is this happening? fu ...

adjusting the dimensions of images to ensure uniformity in size

After many attempts, I am still struggling to resize my image. Can anyone offer assistance? I want all images to have the same dimensions. Here is the HTML code: <link href='https://fonts.googleapis.com/css?family=Indie+Flower' rel='sty ...

Encountering a "Duplicate identifier error" when transitioning TypeScript code to JavaScript

I'm currently using VSCode for working with TypeScript, and I've encountered an issue while compiling to JavaScript. The problem arises when the IDE notifies me that certain elements - like classes or variables - are duplicates. This duplication ...

Issue with jquery curvy corners not functioning properly on Internet Explorer 8

Check out my website at If you view the page in IE8 and then in IE7 compatibility mode, you'll notice a strange issue. The box on the right disappears in IE8 but displays perfectly rounded corners in IE7. I am currently using the jQuery Curvy Corner ...

What is the best way to loop through an object while keeping track of its value types

I have a JSON file containing UI adjustments sourced from the API: interface UIAdjustmentsJSON { logoSize: number; themeColor: string; isFullScreen: boolean; } To simplify things, let's utilize a static object: const adjustments: UIAdjust ...

Angular Karma encountered an error: TypeError - It is unable to read the property '_id' as it is undefined

Encountering an issue while testing with karma jasmine, the error message appears as... TypeError: Cannot read property '_id' of undefined This is the Component.ts file: import { Component, OnInit } from '@angular/core'; import { ApiSe ...

Unable to extract all elements using simple HTML dom when parsing RSS feed

I've been attempting to extract various details like titles, descriptions, links, images, and dates from an RSS feed located at . However, for some reason, I am unable to retrieve the link tag and image source within the feed. The rest of the data ext ...

Fetching Information from Firebase and Populating Dropdown Menus on a Website

Displayed below is a code snippet from a .JSON file stored in a Firebase database. "questionnaires" : { "ORANGE" : { "location" : "ny", "major" : { "engineering" : { "ECE" : { "3rd sem" : { "2018 ...