Slippery carousel: Showcase all items in center alignment mode

Currently, I am implementing Slick Carousel with centerMode. Is there a method to ensure that all items are displayed without being cut off on the screen?

The setup I have is quite simple:

$('.your-class').slick({
  centerMode: true,
  slidesToShow: 2,
  slidesToScroll: 2
});

If you want to check out the code in action, feel free to visit this jsFiddle link.

Answer №1

You have the option to set 'slidesToShow' to 0 in order for all slides to be displayed simultaneously.

However, as pointed out by Developer107 earlier, "this will result in the lack of sliding functionality normally associated with sliders".

$('.your-class').slick({
  centerMode: true,
  slidesToShow: 0,
  slidesToScroll: 2
});

Answer №2

To use the slider array count in your JavaScript, you can create a hidden input field and set its value to the count of slides. Then, retrieve this value in your JavaScript code and pass it to the slidesToShow option after converting it from a string to an integer.

  // Retrieve the count of all slides from the input field
  const slidesCount = document.getElementById('slides_count').value;

$( '.photo_gallery_slider' ).slick({
slidesToShow: 1,
slidesToScroll: 1,
arrows: true,
fade: true,
asNavFor: '.slider-nav'
});
$( '.slider-nav' ).slick({
    // Use the slidesToShow option with custom logic or by parsing the string into an integer.
slidesToShow: (5 >= +slidesCount ? +slidesCount : 5),
slidesToScroll: 1,
asNavFor: '.photo_gallery_slider',
dots: false,
arrows: false,
centerMode: false,
focusOnSelect: true
});
<div class="slider-nav">
  <?php 
  $images = get_field('gallery');
  $counter = 0;
    if ($images) : ?>

        <?php foreach ($images as $image) : $counter++; ?>
          <div>
            <?php if($counter == 1) { ?>
              <input id="slides_count" type="hidden" value="<?=count($images);?>">
            <?php } ?>
            <img src="<?php echo esc_url($image['sizes']['thumbnail']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
            <p><?php echo esc_html($image['caption']); ?></p>
          </div>
        <?php endforeach; ?>
      </ul>
    <?php endif; ?>
  </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 method for emphasizing links in the navigation bar with Bootstrap 3?

I am currently working on applying custom CSS styles to the Bootstrap navbar in order to have the link text underlined when hovered over, with a fade-in effect as well. To see what I have accomplished so far, you can view it here: https://jsfiddle.net/xfd ...

Tips for verifying the input field with specific requirements in Angular 6

There is an input field that needs to validate text based on certain logic conditions: No spaces should be allowed in the formula. The operators (and,or) must be lowercase and enclosed in curly brackets {}. The number of opening '(&apos ...

What is the best way to create a three-column layout that completely fills the width of a page, utilizing pixel measurements on two of the columns

Click here for the jsFiddle link: Is it possible to make div2 and Button2 fill the remaining width of the window while using pixel measurements on columns 1 and 3? This formatting will be applied to a form where a textbox needs to adjust its size based o ...

What is the reason for encountering the error message "Property 'floatThead' does not exist on type 'JQuery<any>' when trying to use floatThead in Angular/TypeScript?

For my project, I am incorporating the third-party jQuery library called https://github.com/mkoryak/floatThead. To work with Bootstrap and jQuery, I have installed them using NPM through the command line. Additionally, I have used NPM to install floatThea ...

Unable to retrieve the most recent global variable value within the confirmation box

<script type="text/javascript"> var customDiv ="hello"; $(function () { var $form = $("#authNotificationForm"); var startItems = $form.serializeArray(); startItems = convertSerializedArrayToHash(startItems); $("#authNoti ...

Maintain the central alignment of the entire page (including the horizontal scrollbar) while zooming in

I have successfully centered elements, but now I am trying to center the entire page (i.e. have the horizontal scrollbar in the middle) when zooming in. Currently, the scrollbar stays at the very left end as I zoom in. * { margin: 0; padding: 0; box ...

Choose items that do not contain ::before or ::after pseudo-elements

I am looking to apply a specific font style to all text on a page except for Font Icons (specifically Font Awesome) which do not share a common class. In order to achieve this, I need to target elements in one of the following ways: Elements that do not ...

Calculating the Sum of Values in PHP using an HTML Form and Jquery

Looking to expand my knowledge of jQuery, I am attempting to create a straightforward page for practice. The goal is to develop a form that will send its values to PHP to be summed and return the results. These results will then be displayed dynamically on ...

Achieve centered alignment for a website with floated elements while displaying the complete container background color

I am currently working on a website that consists of the basic elements like Container, Header, Content, and Footer. The container has a background-color that should cover the entire content of the site, including the header, content, and footer. However, ...

Creating two adjacent squares can be achieved by arranging columns and rows in a specific way

Looking to create a website with a gallery block but running into some issues. I only want to utilize Bootstrap along with my custom CSS for the finishing touches. The layout should consist of 2 squares next to each other, with the left square being 2 colu ...

Is it possible to swap the src of the Next.Js Image Component dynamically and incorporate animations in the

Is there a way to change the src of an image in Nextjs by using state and add animations like fadein and fadeout? I currently have it set up to change the image source when hovering over it. const [logoSrc, setLogoSrc] = useState("/logo.png"); <Image ...

The jQuery.each function creates copies of items during every iteration

Having an issue with my JSON data display on a webpage. Each item appears to be duplicated with every loop iteration, even though the block variable seems correct when logged. I've tried searching for a solution online, but haven't had any luck ...

How can I integrate live data from a MySQL database to automatically update tables on a website?

I have developed a basic application using C# and .NET, with MVC architecture and a MySQL database linked to my server. I have utilized ADO.NET database models to automatically generate static data in my views from the models saved in the database, with ...

Encountering Issues with Formatting InnerHtml Text using RegEx

Technology: React.js I have been working on a custom function in JavaScript to highlight specific words within a code block. The function seems to be functioning correctly, but the highlighting isn't staying after the function is completed. Any ideas ...

The application of border-radius causes the div to extend beyond its intended height

Is there a way to achieve a smooth shadow effect on pictures without it touching the corners? I attempted to do this by adding a border-radius and box-shadow to the parent div of the images, but now the parent div is taller than the picture itself. Any sug ...

Tips for including event information in a form submission using Ajax and jQuery

I have successfully implemented the code below to send a request to the backend using ajax/jquery. My goal: Now, I am looking to dynamically capture form input data when the user interacts with the input fields and include this data in the ajax request. ...

Personalized information boxes for particular data points within highcharts

When hovering over specific points, I want to display unique warnings or explanations in the tooltip. I have included custom text like 'WARNING' and 'WARNING 2' within the series data but am struggling to retrieve that data for each too ...

How about this: "Designing a Pop-Up Window

Currently working on my own customized modal, here's the unique CSS I came up with: .custom-modal{ position: absolute; display: block; top: 0; left: 0; width: 100%; height: 100%; background-color: #000; filter:alpha(o ...

The end of the page is not displayed fully in Safari

I've been scratching my head trying to understand why this Safari browser issue is happening on this page: . It seems to be working perfectly fine on all other browsers that I've tested so far! The code includes some jquery and css to adjust the ...

Is there a way for me to identify the scrolling height and dynamically adjust the title using jQuery?

I am in the process of creating a list of shops from different countries for my website. I want to implement a feature that detects when the user has scrolled to a specific area so I can update the title at the top accordingly. My idea is to assign classe ...