What steps can I take to improve the smoothness of my Slick slider and ensure it functions correctly across all screen widths

I have been experimenting with a carousel slider using Slick Carousel (). My goal is to make it loop infinitely and function smoothly at different browser widths without the cards stacking, but it's not quite working as intended yet. Currently, there is some jerkiness in the loop after 5 slides.

If anyone could offer assistance, that would be much appreciated! I have a demo set up on CodePen! https://codepen.io/cbg/pen/YQdqPQ

<head>

    <style type="text/css">

        body {
            margin: 0;
        }

        #slider {
            background-color: #f5f7f9;
            padding: 80px;
            overflow: auto;
        }

        .service {
            width: 260px !important;
            height: 303px;
            background-color: white;
            float: left;
            margin: 0 15px;
            box-shadow: 0 3px 8px 0 rgba(0,0,0,0.15);
            border-radius: 4px;
        }

        .slick-arrow {
            display: none !important;
        }

        .pod1 {
            background-image: url(fakepods/pod1.png);
        }

        .pod2 {
            background-image: url(fakepods/pod2.png);
        }

        .pod3 {
            background-image: url(fakepods/pod3.png);
        }

        .pod4 {
            background-image: url(fakepods/pod4.png);
        }

        .pod5 {
            background-image: url(fakepods/pod5.png);
        }

    </style>

</head>

<body>

    <div id="slider" class="center slider">
        <div class="pod1 service"></div>
        <div class="pod2 service"></div>
        <div class="pod3 service"></div>
        <div class="pod4 service"></div>
        <div class="pod5 service"></div>
    </div>

    <script src="https://code.jquery.com/jquery-2.2.0.min.js" type="text/javascript"></script>
    <script src="slick.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
    $(document).on('ready', function() {

    $(".center").slick({
    dots: false,
    infinite: true,
    centerMode: true,
    slidesToShow: 4,
    slidesToScroll: 1,
    autoplay: true,
    autoplaySpeed: 250,
    });


    });
    </script>

</body>

Answer №1

Slick is designed to dynamically adjust the size of your boxes based on available space and the number of cards you want to display. To address this, you added !important to your card css width.

Instead of struggling against Slick, leverage its features to achieve the desired widths. Set your slider width to N times the width plus margin of your cards, where N represents the slidesToShow setting. Center it within your parent element using margin auto:

#slider {
  padding: 80px;
  overflow: visible;
  width:1160px;
  margin:0 auto;
}

For responsiveness with smaller browser windows, enclose it in a container with max-width:100% and overflow:hidden.

#container{
  background-color: #f5f7f9;
  overflow:hidden;
  max-width:100%;
  height:100%;
}

This approach works effectively most of the time. Slick duplicates your cards to create an infinite loop effect, occasionally moving them to simulate an endless row of cards. However, on very wide screens with only 5 cards, a blank space may appear at the end. In my example, I doubled your cards so that there are 20 total, adjusted slidesToShow to 9, and increased the width of #slider accordingly.

https://codepen.io/freer4/pen/EXGKXg


To ensure consistent centering of a card, position your #slider inside the #container and enable centerMode by setting it to true.

https://codepen.io/freer4/pen/WOLwLe

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

Enhancing User Experience in Bootstrap 4: Making Dropdown Parents Clickable Links

<nav class="navbar navbar-expand-lg navbar-light bg-light"> <a class="navbar-brand" href="#">Navbar</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbar ...

Is there a way to change an ISO 8601 date into the format '/Date(1525687010053)/' using JavaScript?

Is there a way to convert a date value that is formatted as 9999-12-31T00:00:00Z to the format /Date(1525687010053)/ using javascript? I tried implementing the following code, but it doesn't seem to be working: var datevalue = '9999-12-31T00:00 ...

Design a Bootstrap dropdown menu featuring various options within an icon container

I have designed a blade with a signboard containing multiple columns, each displaying its name, color, and assigned cards (screenshot). To enable sorting of these cards, I added an icon next to each column title. My goal is to allow users to select sorting ...

Slide containing Ionic list views

In my Ionic app, I am using ion-slide-box with 3 slides. Each slide contains an ion-list (table view) with varying numbers of items. The issue is that when scrolling through the shorter list items, it shows empty content due to the taller sibling list taki ...

Creating a Node.js API using express and mysql to retrieve various data including record count, page number, and implementing pagination functionality

How can I efficiently retrieve and display total_record_count, page_number, page_size, total_pages, has_more information in the response while implementing pagination given that I am limiting my query to 100 results? What would be the most effective approa ...

Utilizing Google Places Autocomplete to tailor search outcomes

I'm currently working on customizing the output of my Google Places autocomplete code. Specifically, I want to change the displayed result when a user selects an address from the list. For example, one of the results is: '45 Alexandra Road Holi ...

Exploring Passportjs Callbacks and parsing arguments

I'm struggling to grasp the concept behind the custom callback in Passport.js. I'm not sure why it requires (req, res, next) at the end. Shouldn't these values be obtained from closure? app.get('/login', function(req, res, next) { ...

Connecting a button's action to a specific element in an array using AJAX and Firebase

I am currently working on a project that involves making an AJAX request from a social API and then appending the results with a button inside the div. This button is meant to save the corresponding item in the array to my Firebase database. For brevity, ...

What is the best way to incorporate a dynamic background in NextJS using Tailwind?

I have a poster image that I want to use as a background image, fetched from MovieDb. I tried putting it inside the className like this: className={bg-[url('${path}')] h-screen bg-cover bg-center text-white border-b-8 border-b-solid border-b-sla ...

Tallying the total number of elements within the Item class both pre and post header classes

Hello, I've been brainstorming a JQuery solution to a particular issue. Below, you can see that I have items that come after each heading, which is currently working fine. <div class="header"></div> <div class="item"></div> &l ...

Sending calendar events through ajax response in jQuery FullCalendar can be accomplished by following these steps:

I'm currently using jQuery Fullcalendar in conjunction with Codeigniter. Initially, I have a table that displays schedule times and corresponding names. When I load the calendar page, I send data to fullcalendar.js directly, but I would prefer to rece ...

At what point does a box create an inline formatting context?

According to my research, I came across a situation where a block formatting context is generated as explained in MDN:Block formatting context. I am curious about the scenarios that lead to the establishment of an inline formatting context within a box. ...

A guide to mastering Controllers in AngularJS

Trying to set up a basic page with a controller but encountering difficulties. The HTML code is straightforward, with an Angular script included, but the functionality isn't working as expected. The HTML snippet: <!DOCTYPE html> <html ng-ap ...

Displaying and concealing a div based on the scroll position

I have implemented a script that hides a div and then shows it when I scroll past a certain point on the page. It is working correctly, but once I scroll back up to the top, the div remains visible. Can someone suggest a modification to the code that will ...

The initial setting of [opened]="true" causes an issue with the Angular Material date range picker

Recently, we completed the upgrade of our app from Angular 14 to 15.2.9, which includes Angular Material. The migration process went smoothly, and now our app is compiling and running without any errors. However, we encountered an issue with the mat-date-r ...

Encountered difficulties while attempting to use keyboard input and received a null value when attempting to retrieve a data-* attribute using Python and Selenium

Encountered an issue with keyboard interaction and finding a null value for the data-* attribute during automated login attempts on Gmail using Python and Selenium While attempting to automatically log in to Gmail using Python and Selenium, I successfully ...

Ways to manage numerous AJAX actions within a single HTTP request?

Currently, I am utilizing jQuery to create a multipart web page containing a list of links that are updated through periodic AJAX HTTP requests. Each link on the page is triggered by a timer in JavaScript, causing it to make an HTTP request to its designat ...

`No valid form submission when radio buttons used in AngularJS`

Within my form, I have a single input text field that is required (ng-required="true") and a group of radio buttons (each with ng-model="House.window" and ng-required="!House.window"). Interestingly, I've discovered that if I select a radio button fir ...

A dynamic modal window built with ReactJS

I am struggling to understand how to make my app function properly. There is a component called ContactAdd that should render the component ModalWindow when clicked. The ModalWindow component requires a parameter called isOpened={this.state.open}. How c ...

Instructions for implementing this script in HTML and JavaScript: utilize the clone() function

I came across this code snippet here function displaytickets(){ var $panel = $('<div/>').addClass('col-xs-3 panel panel-default') $panel.append($('<div><h3 class="panel-title">Title</h3></div>&a ...