Using Slick.JS to Sync Navigation with Main Slider, Automatically Resetting to First Slide

I have a question about the functionality of the Slick.JS plugin that I'm using. In my project, I have two carousels with five slides each. The top carousel displays one slide at a time, while the bottom carousel shows all five slides concurrently. My goal is to synchronize these two carousels so that when a user clicks on a slide in the bottom carousel, the top carousel moves to the corresponding slide, and vice versa.

To illustrate how I want this synchronization to work, please refer to the following example: https://codepen.io/pjmtokyo/pen/JYyjew. Another example of slider syncing can be found here: .

Currently, when I click the arrows on the top navigation, the bottom carousel updates correctly by adding the "slick-active" class to the appropriate slide. However, clicking on a slide in the bottom carousel always resets the top carousel to the first slide. What am I missing here to ensure that clicks on the bottom carousel update the top carousel accordingly?

Here are the Slick Options I've defined (using slick.1.4.1 with jQuery 3.2.1):


# HOMEPAGE WHO WE SERVE SLIDER
homepageWhoWeServeSlickOptions =
slidesToShow: 1,
slidesToScroll: 1,
arrows: true,   
asNavFor: '.home-serve-icons',

homeServeIconsOptions =
slidesToShow: 5,
slidesToScroll: 1,
asNavFor: '.home-serve-scroll',
arrows: false,
focusOnSelect: true
$('.home-serve-scroll').slick(homepageWhoWeServeSlickOptions)
$('.home-serve-icons').slick(homeServeIconsOptions)

$('.home-serve-icons .slick-slide').removeClass 'slick-active'
$('.home-serve-icons .slick-slide').eq(0).addClass 'slick-active'

$('.home-serve-scroll').on 'beforeChange', (event, slick, currentSlide, nextSlide) ->
mySlideNumber = nextSlide
$('.home-serve-icons .slick-slide').removeClass 'slick-active'
$('.home-serve-icons .slick-slide').eq(mySlideNumber).addClass 'slick-active'
return

The HTML code that Slick targets in my project is as follows:

{% from '_macros/button' import button as m_button %}
{% set whoWeServe = craft.entries.section('homepageWhoWeServe').limit(5) %}
<section>
    <div class="container">
        <div class="row">
            <div class="col-md-10 col-md-offset-1">
                <div class="home-serve-scroll" style="padding: 0px 40px;">
                    {% for entry in whoWeServe.all() %}
                        <div id="serve-{{ loop.index }}">
                            <h2>{{ entry.title }}</h2>
                            {{ entry.whoWeServeDescription }}
                            {% set destination = entry.whoWeServeLandingPage.one.getUrl() %}
                            {% set text = entry.whoWeServeCtaText | default("Learn More") %}
                            {{ m_button(destination, text, {classes:'important-cta-button'}) }}
                        </div>
                    {% endfor %}
                </div>
            </div>
        </div>
        <div class="col-md-10 col-md-offset-1">
            <div class="home-serve-icons">
                {% for entry in whoWeServe.all() %}
                    <div id="serve-icon-{{ loop.index }}">
                        {{ entry.title }}
                    </div>
                {% endfor %}
            </div>
        </div>  
    </div>
</section>

Answer №1

After some troubleshooting, I managed to resolve the issue at hand. Gouigouix's suggestion proved to be the key: https://github.com/kenwheeler/slick/issues/649

Essentially, it was crucial to have a proper HTML tag within the container div for everything to function correctly. Previously, I only had a div containing some plain text without any wrapping tags. So making this adjustment:

    <div class="col-md-10 col-md-offset-1">
        <div class="home-serve-icons">
            {% for entry in whoWeServe.all() %}
                <div id="serve-icon-{{ loop.index }}">
                    {{ entry.title }}
                </div>
            {% endfor %}
        </div>
    </div>  

to this:

    <div class="col-md-10 col-md-offset-1">
        <div class="home-serve-icons">
            {% for entry in whoWeServe.all() %}
                <div id="serve-icon-{{ loop.index }}">
                    <p>{{ entry.title }}</p>
                </div>
            {% endfor %}
        </div>
    </div>  

Made all the difference. Hopefully, this solution can assist others facing a similar problem!

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

Set the local storage value to the $scope variable

I am attempting to set a local storage value to a $scope variable and utilize that $scope variable in ng-model to populate dropdowns. However, the code I have tried is not functioning as expected. You can view the Plunker example here: https://plnkr.co/ed ...

Can Vue.js 3 composition be leveraged with v-for to incorporate a query string into a router-link?

I have successfully implemented v-for for a URL path. Now, I am looking to merge the URL path with the query string in the router link tag. The query string will be the date from each item rendered by v-for. Is there a way to dynamically pass this query ...

Utilizing AMAZON_COGNITO_USER_POOLS in conjunction with apollo-client: A comprehensive guide

Struggling to populate my jwtToken with the latest @aws-amplify packages, facing some challenges. Encountering an error when attempting to run a Query: Uncaught (in promise) No current user It seems that when using auth type AMAZON_COGNITO_USER_POOLS, I ...

Creating an arrow dialog box in Material UI: A step-by-step guide

I have successfully created an arrow box (div) using custom CSS and HTML. However, I am facing difficulty in implementing the same design in Material UI with React JS. The code below demonstrates how to achieve this using custom CSS. My question is: How ...

PHP is not processing the HTML form I submitted

HTML: <form method="post" action="create.php"> Job #: <input type="text" name="jobnum"> <br> Program: <input type="text" name="program"><br /> Ship Date: <input type="text" name="shipdate"><br /> Description: < ...

Security Error when using the JavaScript map function in FireFox

My current dilemma involves using a JavaScript code to extract the above-the-fold CSS from my websites. Surprisingly, it functions flawlessly on Google Chrome. However, when I attempt to execute it on Firefox, an infamous 'SecurityError' occurs: ...

Ensuring Data Integrity in Angular JS Forms

I've been working on submitting a blank form that triggers custom error messages on mandatory fields. The validation is working perfectly, but I'm running into an issue when the form is loaded for the first time and the user clicks directly on th ...

Centralizing images in a Facebook gallery/lightbox during the loading process

Is the image width and height stored in Facebook's gallery database? In typical JavaScript usage, the image width and height cannot be determined until the image is fully loaded. However, on Facebook, images are pre-loaded before being displayed, ens ...

Change the x and y positions of several div elements as the mouse moves in JavaScript

I am aiming to create a webpage where multiple divs with text and other content move along the x and y axes of the mouse. The desired effect is similar to parallax scrolling, but I have found that existing parallax plugins are image-based and do not work w ...

Control and manage AJAX POST requests in the controller

I'm currently working on implementing an ajax post request feature in my project. The goal is to have a button on my html page trigger a javascript event listener, which then initiates an ajax post request to receive some text data. However, I seem to ...

NodeJS guide: Enabling cross-domain access for web services

Currently, I am developing a nodejs server and facing the challenge of needing to access additional services through ajax from a different domain. Can anyone provide guidance on how to bypass the cross-domain restriction within nodejs code? Please note th ...

Two distinct controllers: concealing elements through the operation of one of them

I am facing a challenge with my HTML elements: In one form-group, I have the following input: <div class="form-group"> <input type="search" ng-model="search"/> </div> This particular form-group needs to be hidden when another form-g ...

Changing the value of a button using the slideToggle() function

Currently, I am experimenting with this example. Is there a way for me to modify the button text using the slideToggle() function? My goal is to switch the text between Show and Hide. Below is my current code snippet: <button id="boxToggle">Show&l ...

Encountering an error message stating "Unable to read property 'map' of undefined while attempting to create drag and drop cards

I have incorporated the library available at: https://github.com/clauderic/react-sortable-hoc The desired effect that I am aiming for can be seen in this example: https://i.stack.imgur.com/WGQfT.jpg You can view a demo of my implementation here: https:// ...

Angular error message: Trying to access the property 'name' of an undefined object leads to a TypeError

I'm having trouble phrasing this question differently, but I am seeking assistance in comprehending how to address this issue. The error message I am encountering is as follows: TypeError: _co.create is not a function TypeError: Cannot read property ...

Update the value of a td element when a select option is changed in another td element within the same table row

I have a table set up as follows: Header1 | Header2 | Header3 | Header 4 | Header 5 Row 1 |<span>Some Text</span> | <select></select> Row 2 Row 3 . . . . Rows generated dynamically. My objecti ...

Is it possible to trigger a method on the current PHP page as well as a method in another PHP script at the same time when submitting a form using jQuery Ajax

Can someone assist me? I am new to PHP and feeling overwhelmed with the PHP request process. Implementing an MVC structure for view, I have created an HTML form. When the form is submitted, I need to execute two different methods - sendMail() and validate ...

Producing asynchronous JavaScript events using a browser extension (NPAPI)

Currently in the process of developing a web browser plugin using NPAPI. The issue I am facing is that my plugin requires a worker thread to handle certain tasks, and I need to pass events back to JavaScript as the worker progresses. However, due to the N ...

The Django form returns as not valid during an AJAX request as form.is_valide() is False

I have a form for uploading a model that includes an ImageField, and I want users to be able to submit images via AJAX. The issue is that form.is_valid() returns False. Everything works fine when not using AJAX. I've tried several solutions from simi ...

Angular: Modifying the parent scope from a child component

Hey there! So I'm a beginner in this whole programming thing, but I'm currently working on a small application where I can add and update items with details using Ionic, Cordova, and AngularJS. However, I've hit a roadblock with the followin ...