Switch up the current Slick Carousel display by utilizing a div element

We have implemented the slick carousel to show only one slide at a time within the

<div class='item__wrapper'>
. Beneath this are three items, and we want the slick carousel to update when any of these items are clicked.

Issues

  1. Using item__boxes as a slick carousel causes styling conflicts, preventing us from using $('.item__boxes).slick({});
  2. Clicking on any item in item__boxes always sets the item__wrapper to slide 3

Query

  • How can we configure the item__boxes so that clicking on an item aligns with our intended outcomes? For example, clicking on the second item should set the item__wrapper to the second slide.

Goal/Expected Results:

  1. Clicking on the first item should make the first slide active in item__wrapper
  2. Clicking on the second item should activate the second slide in item__wrapper
  3. Clicking on the third item should display the third slide as active in item__wrapper
  4. Achieve goals 1-3 without utilizing $('.item__boxes).slick({});

Code:

$('.item__wrapper').slick({

          infinite: true,
          speed: 1500,
          dots: false,
          prevArrow: false,
          nextArrow: false
});

$('.item__boxes').on('click', function() {

var slickIndex = $(this).attr('data-slick-index');
$('.item__wrapper').slick('slickGoTo', slickIndex);
});
.filter {
  width: 100%;
  height: 100%;
  padding: 45px;
  margin-right: -45px;
}
.item {
  display: none;
  position: relative;
}
.item.active {
  display: block;
}
.item1 {
  background-image: url("https://placeimg.com/1000/480/nature");
}
.item2 {
  background-image: url("https://placeimg.com/640/480/arch");
}
.item3 {
  background-image: url("https://placeimg.com/640/480/tech");
}
.item__wrapper {
  max-width: 60%;
  position: relative;
  background-size: cover;
  background-repeat: no-repeat;
  background-color: rgba(238, 238, 238, 0.5);
}
.item__img img {
  top: 0px;
  position: absolute;
  width: 100% !important;
  opacity: 0.5;
}
.item__text {
  top: 0px;
  position: relative;
  min-height: 100%;
  line-height: 1.4;
  padding-right: 70px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: top;
  justify-content: center;
}
.item__boxes {
  display: flex;
  position: relative;
  opacity: 0.9;
}
.item__boxes > div {
  border: 1px solid;
}
.col-padding {
  padding: 16px 16px 5px 16px;
}
.col-m-12 {
  width: 100%;
}
@media (min-width: 1024px) {
  .col-t-6 {
    width: 50%;
  }
}
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.css"/>

<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick-theme.css"/>
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.js"></script>

<div class="item__wrapper">
   <div class="item active" id='item1'>
<div class="item__text">
<div class="filter">
<h3>Some title 1</h3>
<p>Efficiently communicate sticky quality vectors after compelling growth strategies. Compellingly scale future-proof content rather than enterprise users. Uniquely build scalable applications vis-a-vis performance based functionalities. Monotonectally procrastinate.</p>
</div>
</div>
    </div>
  <div class="item active" id="item2" >
        <div class="item__text">
<div class="filter">
<h3>Some title 2</h3>
<p>Efficiently communicate sticky quality vectors after compelling growth strategies. Compellingly scale future-proof content rather than enterprise users. Uniquely build scalable applications vis-a-vis performance based functionalities. Monotonectally procrastinate.</p>
</div>
</div>
    </div>
  <div class="item active"  id="item3" >
        <div class="item__text">
<div class="filter">
<h3>Some title 3</h3>
<p>Efficiently communicate sticky quality vectors after compelling growth strategies. Compellingly scale future-proof content rather than enterprise users. Uniquely build scalable applications vis-a-vis performance based functionalities. Monotonectally procrastinate.</p>
</div>
</div>
    </div>

   
</div>
<div class="item__boxes">
     <div class="box col-m-12 col-t-6 col-padding" data-slick-index="-1">
<div>Some Title</div>
<div>Enthusiastically incubate diverse initiatives without multifunctional strategic theme areas.</div>
</div>
<div class="box col-m-12 col-t-6 col-padding" data-slick-index="0">
<div>Globally Title</div>
<div>Globally impact integrated infomediaries via seamless mindshare. </div>
</div>
<div class="box col-m-12 col-t-6 col-padding" data-slick-index="1">
<div>Distinctively Title</div>
<div>Distinctively strategize long-term high-impact ideas whereas client-centered leadership skills.</div>
</div>
</div>

Answer №1

Give this a shot.

$('.item__wrapper').slick({
  infinite: true,
  speed: 1500,
  dots: false,
  prevArrow: false,
  nextArrow: false
});

$('[data-slide]').click(function(e){
  var slideno = $(this).data('slide');
  $('.item__wrapper').slick('slickGoTo', slideno);
});
.filter {
  width: 100%;
  height: 100%;
  padding: 45px;
  margin-right: -45px;
}
.item {
  display: none;
  position: relative;
}
.item.active {
  display: block;
}
.item1 {
  background-image: url("https://placeimg.com/1000/480/nature");
}
.item2 {
  background-image: url("https://placeimg.com/640/480/arch");
}
.item3 {
  background-image: url("https://placeimg.com/640/480/tech");
}
.item__wrapper {
  max-width: 60%;
  position: relative;
  background-size: cover;
  background-repeat: no-repeat;
  background-color: rgba(238, 238, 238, 0.5);
}
.item__img img {
  top: 0px;
  position: absolute;
  width: 100% !important;
  opacity: 0.5;
}
.item__text {
  top: 0px;
  position: relative;
  min-height: 100%;
  line-height: 1.4;
  padding-right: 70px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: top;
  justify-content: center;
}
.item__boxes {
  display: flex;
  position: relative;
  opacity: 0.9;
}
.item__boxes > div {
  border: 1px solid;
}
.col-padding {
  padding: 16px 16px 5px 16px;
}
.col-m-12 {
  width: 100%;
}
@media (min-width: 1024px) {
  .col-t-6 {
    width: 50%;
  }
}
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.css"/>

<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick-theme.css"/>
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.js"></script>

<div class="item__wrapper">
   <div class="item active" id='item1'>
<div class="item__text">
<div class="filter">
<h3>Title One</h3>
<p>Description for title one.</p>
</div>
</div>
    </div>
  <div class="item" id="item2" >
        <div class="item__text">
<div class="filter">
<h3>Title Two</h3>
<p>Description for title two.</p>
</div>
</div>
    </div>
  <div class="item"  id="item3" >
        <div class="item__text">
<div class="filter">
<h3>Title Three</h3>
<p>Description for title three.</p>
</div>
</div>
    </div>

   
</div>
<div class="item__boxes">
     <div class="box col-m-12 col-t-6 col-padding" data-slide="0">
<div>Some Title</div>
<div>Description.</div>
</div>
<div class="box col-m-12 col-t-6 col-padding" data-slide="1">
<div>Globally Title</div>
<div>More Description</div>
</div>
<div class="box col-m-12 col-t-6 col-padding" data-slide="2">
<div>Distinctively Title</div>
<div>Another Description.</div>
</div>
</div>

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

What is the fallback mechanism in Astro js when the cache is unavailable?

When the cache is not accessible in Next.js, the page will be server-side rendered and displayed using either the true or blocking fallback approach. I am curious about the approach taken by Astro.js in this situation. I am planning to develop a dynamic b ...

An issue has occurred: Cannot access the properties of an undefined object (specifically 'controls')

I encountered an error message stating "TypeError: Cannot read property 'controls' of undefined" in the code that I am not familiar with. My goal is to identify the source of this error. Below is the HTML code snippet from my webpage: <div ...

Using Jquery to run a jquery script stored in a variable within jQuery syntax

This question may seem a bit confusing, so allow me to explain further. I am trying to execute a jquery script that is written in a text file obtained through an ajax request. For example, the code I receive from the ajax request looks like this: ($($(" ...

The Date Picker pops up automatically upon opening the page but this feature is only available on IE10

There seems to be an issue with the date picker opening automatically on IE10, while it works fine in Firefox where it only appears when you click on the associated text box. Does anyone have insight into why this might be happening specifically in IE10? ...

Error in React .js: Unable to access property 'name' as it is undefined

I keep encountering this issue: Uncaught TypeError: Cannot read property 'name' of undefined In my code, I have a user object defined in the App.js file. However, when I attempt to access its properties within my Person component, it throws a ...

Using JQUERY to create a smooth sliding transition as images change

Currently, I have set up three images (1.jpg, 2.jpg, 3.jpg) along with an image using the code: <img id="add" src="1.jpg"></img>. The width, height, and position of this additional image are adjusted as needed and are functioning correctly. Fur ...

Eliminate a descendant of a juvenile by using the identification of that specific juvenile

Here is the current structure I'm working with: I want to figure out how to eliminate any field that has the id 3Q41X2tKUMUmiDjXL1BJon70l8n2 from all subjects. Is there a way to achieve this efficiently? admin.database().ref('UsersBySubjects&ap ...

Create a unique margin using CSS only that will appear at the bottom of a flex-row container that scrolls

I'm trying to create a horizontal scroller with margins between each item and consistent margins at both ends. However, I'm noticing that the margin at the end of the container seems to be disappearing somehow. Is there a way to maintain the mar ...

Returning Props in Dynamic Components with Vue 3

Exploring the capabilities of Vue3's Dynamic Component <component>, I am currently working with this setup: Component 1: <template> <div> <h1> Name Input: </h2> <Input :model="props.name" /> ...

Restrict the duplication of div elements with JQuery

Here is the structure I'm working with: <div class="checkmark-outer"> <div class="checkmark-33"> <div class="fa-stack fa-1x checkmark-icon"> <i class="fa fa-circle fa-stack-2x icon-background"></i> ...

Search for Instagram images with a specific tag using jQuery and AJAX

I am looking to create a feature where users can enter a tag and view recent media related to that tag. I attempted to implement this code but encountered an error in the Chrome Console. "https://api.instagram.com/v1/tags//media/recent?callback=jQuery2240 ...

How can you efficiently update another ng-model value based on a select input in AngularJS using ng-change?

<select data-ng-init="selectedItem='previewWidth = 1920; previewHeight = 1080'" data-ng-model="selectedItem" data-ng-change="GetNewData(); {{selectedItem}}"> <option value="previewWidth = 1920; previe ...

Using the preselection feature in the MUI DataGrid can cause the grid to become disabled

I am customizing a mui datagrid to have preselected rows using the following code snippet: const movieCrewList = movieCrew.map((item) => item.id); const [selecteTabledData, setSelectedTableData] = React.useState([]); <DataGrid rows={crewData} c ...

The list in the navbar is misaligned and not centered vertically within the flex container

I've been working with flex for a while now, but I'm struggling to vertically align the content of my navbar to the center in the code. <nav className="nav navbar"> <h3> Logo </h3> <ul className= &q ...

Is there a way to retrieve the objects generated by DirectionsRenderer on Google Maps V3?

Is there a simple method to access the objects and properties of the markers and infowindows that are generated by the DirectionsRenderer? (such as the "A" and "B" endpoints of the route) I want to swap out the infowindows for the "A" & "B" markers wi ...

Display the contents of a <div> tag from one HTML file onto another HTML file

Recently I embarked on learning HTML and came across a peculiar doubt. My goal is to create a section div on the first page that changes dynamically based on the menu item clicked, rather than redirecting to another HTML page. I've experimented with s ...

Obtain the ID of element 1 by clicking on element 2 using JQuery

In the world of javascript/jquery, When button1 is clicked, we can get its id like this: var button1id = $(this).attr("id"); If button2 is clicked, how do we retrieve button1's id? This brings us to the question: How does button2 access the i ...

What is the reason behind caching form data in an ajax call?

After the first successful submission, I am facing an issue where the original form data is being re-sent even when new values are submitted for a second attempt. How can I reset and reload the data to avoid this problem? I have tried several approaches i ...

Understanding jest.mock: Verifying the invocation of a nested function

I have a section of code in my application that looks like this: import validationSchema from "./../_validation/report"; const reportModel = require("../models/report"); ctrl.addReport = async (req, res) => { const { body } = req; try { cons ...

When comparing two state arrays in React, it is important to note that they will not be considered equal and return a boolean (True

As I attempt to compare two arrays stored in my state, my goal is to set a boolean variable to "true" if they match. However, my current if statement fails to detect equality between the arrays. I'm performing this comparison within a setInterval() f ...