The issue with the Hidden Content feature in the Slick Carousel is that it does not function correctly on the

There are some related topics worth exploring, such as: Slick carousel center class not working when going from last item to first item

Despite trying various solutions, the issue still persists in my code. My goal is to have each item displayed in the center with the rest hidden, except for the first and last items. Click on "item 8" and "item 1" below to see what I mean.

I am really in need of assistance with this problem and would greatly appreciate any advice or suggestions. Please help!

$('.slick-wrap').slick({
      dots: false,
      focusOnSelect: true,
      infinite: true,
      arrows: false,
      speed: 300,
      slidesToShow: 5,
      slidesToScroll: 1,
      centerMode: true,
      centerPadding: '30px',
      responsive: {
          600: {
              items: 2
          }
      }
 });


    $('.slick-wrap').on('init', function(event, slick){
        var carouselTexts = $(".slick-item .cont-hide");
        var idx = $(event.target).find('.slick-list .slick-center').index();
        carouselTexts.eq(idx).css('visibility', 'visible');
    });

    //display and hide the content
    $('.slick-item').on('click', function() {
        var carouselTexts = $(".slick-item .cont-hide");
        var clickedNum = $(".slick-item").index(this);

        carouselTexts.not(clickedNum).css('visibility', 'hidden')
        carouselTexts.eq(clickedNum).css('visibility', 'visible');
    });
.slick-section{
    padding: 25px;
    text-align: center;
}
.slick-container{
    width: 100%;
    margin: 0 auto;
}
.slick-wrap{
    margin: 0 -10px;
}
.slick-item{
    padding: 0 10px;
}

.slick-dots {
    list-style-type: none;
    margin: 25px 0 0;
    padding: 0;
}
 .slick-dots li {
    width: auto;
    height: auto;
    display: inline-block;
    padding: 0 5px;
 }

 .slick-active button{
     background: #ccc;
 }
 
.cont-hide{ visibility: hidden; }
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4d7c8cdc7cf89c7c5d6cbd1d7c1c8e4958a9c8a95">[email protected]</a>/slick/slick.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1f6c73767c74327c7e6d706a6c7a735f2e31">[email protected]</a>/slick/slick.min.js"></script>

<section class="slick-section">
  <div class="slick-container">
    <div class="slick-wrap">
        <div class="slick-item">1 <div class="main-panel cont-hide">test 1</div></div>
        <div class="slick-item">2 <div class="main-panel cont-hide">test 2</div></div>
        <div class="slick-item">3 <div class="main-panel cont-hide">test 3</div></div>
        <div class="slick-item">4 <div class="main-panel cont-hide">test 4</div></div>
        <div class="slick-item">5 <div class="main-panel cont-hide">test 5</div></div>
        <div class="slick-item">6 <div class="main-panel cont-hide">test 6</div></div>
        <div class="slick-item">7 <div class="main-panel cont-hide">test 7</div></div>
        <div class="slick-item">8 <div class="main-panel cont-hide">test 8</div></div>
     </div>
  </div>
</section>

Answer №1

$('.gallery-item').on('click', function() {
        var galleryDescriptions = $(".gallery-item .description");
        var clickedIndex = $(".gallery-item").index(this);

    $('.gallery-item .description').each(function(i, obj) {
        jQuery(this).css('display', 'none');
    });

    jQuery(this).children('.description').attr('style','display: block');
});

$('.gallery-wrap').on('afterChange', function (event, slick, currentSlide) {
    var element = slick.$slides.get(currentSlide);
    
    var elements = $(element);
    var target = $('.description', elements);
    target.attr('style','display: block');
    target.removeClass("hidden");
    
    var currentIndex = $(element).data('slick-index');
});

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 functioning of JavaScript's ajax capabilities

Need some help with a coding issue I'm facing. Can anyone provide suggestions for improving my code? I've come across a situation where the table is not updating when using a certain piece of code. However, upon further inspection, I found that ...

What steps do I need to follow to upload an image file through Socket.IO?

For my school project, I am developing a chat application and facing a challenge with implementing an onClick event to trigger a function that utilizes socket-io-file-upload to prompt the user to select a file for upload. This functionality is detailed in ...

The unique format created by tinyMce is not being displayed

I am trying to customize the style format of my tinyMCE, but I am having trouble getting it to show up. Can anyone suggest what might be going wrong? Where should I place the button "Formats" so that I can choose a specific style? tinyMCE.init({ mod ...

Any tips on how to retrieve parameters from a $.post request?

After learning about $.post, I have both PHP and HTML code that I'm working with. My goal is to later utilize specific elements from the result array, such as FileName and Width. How can I achieve this? Here is the PHP code snippet: <?php $jso ...

Updating the .css file through the graphical user interface, within the managed bean

I have created a jsf page with colorpickers to allow an administrator to modify the main theme of the site, which consists of 4 colors. I have prefixed my main colors in the css file with numbers like this: .element{ background: /*1*/#333333; } When ...

What is the proper way to define the type for a functional React component by using object destructuring on props?

As I continue to learn TypeScript and work on declaring advanced types, I am faced with converting my CRA project to TypeScript. Within this project, I have a component that closely resembles examples from react-router-dom, but I have not come across any T ...

Protractor: How to Handle Multiple Browser Instances in a Non-Angular Application and Troubleshoot Issues with ignoreSynchronization

I have encountered an issue while using protractor to test a Non-Angular application. After implementing the browser.forkNewDriverInstance(), it appears that this function is no longer functioning correctly as I am receiving the following error message dur ...

Generating a preview image for a three.js environment

I am currently working on a website dedicated to visualizing the biological neurons found in animals. I have a comprehensive list of neuron names, and I use THREE JS to draw the neuron when the user clicks on its name. However, with hundreds of neurons to ...

How to vertically align an image within a div that has a variable height

Is there a way to center an image vertically within a div that is 1/5 of the screen's height? I have managed to horizontally center the image, but vertical alignment seems tricky. Here's the code I've tried so far: http://jsfiddle.net/ws911 ...

Enclose a pair of divs within a fresh div wrapper for better organization

Imagine you have the following: <div class="somediv"></div> <div class="somediv"></div> <div class="somediv"></div> <div class="somediv"></div> <div class="somediv"></div> <div class="somediv" ...

Storing data in the browser's LocalStorage after a Vue3 component has

Whenever a user successfully logs into the application, a nav bar is supposed to load user data. However, there seems to be a timing issue with localStorage being set slightly after the nav bar is loaded. Using a setTimeout() function resolves the issue, b ...

Show a Toast in React without relying on useEffect to manage the state

I have successfully implemented the Toast functionality from react-bootstrap into my application using the provided code. However, I am unsure if it is necessary to utilize useEffect to set show with setShow(items.length > 0);. Would it be simpler to ...

Is it possible to create a custom options array in React-Select?

I've been working with react-select using the package from . The required format for the options prop is {value:something, label:something}. I have a list of objects with additional key-value pairs and I'm wondering if there's a way to avoi ...

Real-time Updates for JQueryUI Tooltip on Mobile Devices

I have a follow/unfollow button with jQuery UI tooltips that display the button's title. I want to update the tooltip content immediately when the button is clicked, without requiring the user to move their mouse away and back over the button. Here is ...

Having trouble with JavaScript canvas drawImage function not functioning correctly

Having some trouble drawing part of an image properly. The width and height are not matching the original. Check out my code below: window.onload = function() { ImageObjSketch = new Image(); // URL ImageObjSketch.src = 'https://i.imgur.com/75lATF9 ...

The React context is currently yielding an undefined value

I am puzzled by this issue. I have double-checked to ensure that the states value is not undefined, and it isn't. However, I am unable to pinpoint where I may be making a mistake. Here is my authContext.js file: const initialState = { isAuthorized: ...

Disappearing PHP Session following a redirection

I'm encountering an issue with the LDAP Authentication redirection in my system. When I access Index.php, it correctly redirects me to the login page (login.php). However, after entering my credentials, it fails to redirect me back to the Index Page. ...

React component for a background image with a gradient overlay

I'm facing an issue trying to incorporate a background image for a div along with a color overlay. In plain CSS, the code would typically look like this: .backgroundImage { background-image: linear-gradient(to bottom, rgba(245, 246, 252, 0.52), rg ...

Exploring the Power of Ajax Integration with Mongodb

I have been trying to figure this out for a while now, but I'm lost. I am attempting to use Ajax to retrieve information from a collection named 'reizen' in MongoDB. My goal is to cycle through all elements within the collection and extract ...

Module Augmentation for extending Material UI theme is not functioning as expected

I'm having trouble expanding upon the Theme with Material UI because an error keeps popping up, indicating that I am not extending it correctly. The error message states: Property 'layout' is missing in type 'Palette' but required ...