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

In JavaScript, find a value in an array and substitute it with the value from the

One of my tasks involves manipulating a string variable in the following manner: domNodes += '<a href="javascript: void(0);" data-role="node_jump" data-node="'+this.tagName.toLowerCase()+'">'+this.tagName + "</a>" + " & ...

Anticipate the middleware function to either invoke the next function or return a HTTP 400 status code

I am eager to delve into unit testing and am looking to test my Node API. I am utilizing Express with Typescript and Jest for testing. Prior to invoking the controller middleware, I apply the route input validation middleware to verify the validity of the ...

Is there a way to streamline the import process for material-ui components?

Is there a shortcut to condense all these imports into one line? As a newcomer to react, I've noticed that every component must be individually imported, especially when it comes to CSS components. Could you provide me with a suggestion on how to st ...

Gravity forms: AJAX-loaded checkboxes become unchecked due to validation errors

Gravity Forms is being used to dynamically load checkboxes based on a dropdown selection through AJAX. Everything functions correctly until the form is submitted with invalid data (such as leaving a required field empty), causing all checkboxes to become u ...

Combine the data retrieved from an AJAX call with the original source for autocomplete suggestions

$(function() { $("#search").autocomplete({ source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"] }).focus(); $.ajax({ url: "source.php", success: function(result) { return result; ...

Issue: Undefined onClick function for HTML when using Node.js, NPM, and Parcel

I am currently working on a weather application using Node.js, NPM, and Parcel for development. To ensure OpenLayers functions properly, I need to incorporate these technologies, even though I'm not very familiar with them. One key aspect of my proje ...

Combining TypeScript and JavaScript for efficient mixins

I came across an article on MDN discussing the usage and creation of mix-ins (link). Intrigued, I decided to try implementing it in TypeScript: type Constructor = new (...args: any) => any; function nameMixin(Base: Constructor) { return class extends ...

Issue with marker functionality on Google Maps JavaScript API when conditions are not functioning correctly

I am currently working on plotting different markers on Google Maps by extracting data from a CSV file. I have incorporated the parsecsv-0.4.3-beta library to read the CSV file, and everything is functioning smoothly except for when I compare two fields to ...

One might encounter undefined JSON keys when attempting to access them from a script tag

During my attempts to load a specific Json using an Ajax GET request and then parsing it, I encountered an issue when trying to access the Json key from an HTML script tag, as it returned as undefined. To troubleshoot this problem, I decided to log all th ...

Encountering an issue while trying to initiate a fresh React Native Project

As I work through the setup steps outlined in the React Native Documentation on my M1 MacBook Pro, I encounter a stumbling block. Despite successfully running React projects and Expo projects on this machine before, I hit a snag when trying to create a new ...

Modal failing to update with latest information

My webpage dynamically loads data from a database and presents it in divs, each with a "View" button that triggers the method onclick="getdetails(this)". This method successfully creates a modal with the corresponding data. function getdetails(par) { ...

What steps do you need to take in order to transform this individual slideshow script into numerous slideshows

I came across this code online that effectively creates a slideshow. https://css-tricks.com/snippets/jquery/simple-auto-playing-slideshow/ Is there a way to modify the code to support multiple slideshows? I've made several attempts without success ...

The function to use Jquery UI .slider is missing

Looking to implement the range slider from jQueryUI in my Laravel project, but encountering an error despite having both jQuery and jQueryUI included. Upon inspecting the sources, I can see that both files have been loaded. <head> ... <!- ...

Preserve multiple selected values post form submission using PHP, HTML, and JavaScript

How can I retain the selected values in a form after it is submitted? My current code functions correctly when only one value is selected, but does not maintain all selected values when multiple are chosen simultaneously. Any assistance would be apprecia ...

Encountering HTML content error when attempting to log in with REST API through Express on Postman

I'm currently in the process of developing a basic login API using Node.js and Express. However, I've encountered an error when testing with Postman: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

What could be causing the issue with the array.push method not functioning

i have come across this piece of code function fetchImagesList(errU,errorsList) { if(errU) throw errU; var directories=new Array(); var sourceDir=''; var destinationDir=''; if(errorsList==&a ...

Generating random values from an array in PHP without the need to refresh the page

Lately, I've been delving into the world of PHP for the first time in a project. However, I've encountered a problem that has me stumped – despite scouring various questions on Stack Overflow. My issue involves randomizing values from an array ...

You are required to select one of the two radio buttons in order to proceed with the validation process

To prevent the user from proceeding to the next page, validation is necessary. They are required to select one of the radio buttons, etc. <div class=""> <div class="radiho" style="display: block"> <input type="checkbox" name="sp ...

Phone Validation for Contact Form 7

Recently, I was tasked with creating a landing page for a job interview. The challenge was to include validation on the phone number field so that it has to be between 9 and 10 numbers in length, along with another validation requiring the phone number t ...

Challenges in the functionality of PHP form submission utilizing GET parameters

I'm currently working with PHP forms and the form tag I have looks like this: <form name="adv_search_form" action="<?php echo $targetpage; ?>" method="GET"> When I submit the form, it directs me to this URL: http://localhost/projectcode ...