Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Slick Slider: How to scroll less than one entire slide

Using Slick Slider I'm trying to create a carousel that on the first slide it will show 75% of the slide and when scrolling it should only show 75% of the next slide.

First slide only showing 75% and then 25% of next slide enter image description here

What is happening: Shows 75% of next slide but does not show 25% of previous slide enter image description here

What I am trying to accomplish: Show 25% of the previous slide and 75% of current slide
enter image description here

My current Slick Config is:

$('.myCarousel').slick({
    arrows: false,
    infinite: false,
    slidesToShow: 0.75,
    slidesToScroll: 1,
    variableWidth: true
})

I've tried changing the slidesToScroll property to 0.75 with zero success. It seems that anything less than 1 and Slick Slider refuses to change slides.

I've also found that I can have my slider element, in this example .myCarousel, watch for the swipe event. I've thought about attempting to change the transform: translation(#px, #px, #px) on the carousel container, .myCarousel, with JS but I feel there must be an easier way.

Carousel HTML

<div class="gateway_nav">
    <div class="border_right__red">
        <div>
            <a href="" class="gateway_nav__gateway_title">ASD</a>
        </div>
        <div class="gateway_nav__slider_element">
            <a href="">ASDFG</a>
        </div>
        <div class="gateway_nav__slider_element">
            <a href="">ASDFGH</a>
        </div>
        <div class="gateway_nav__slider_element">
            <a href="">ASDFGHJKL</a>
        </div>
    </div>

    <div>
        <div>
            <a href="" class="gateway_nav__gateway_title">QWERT</a>
        </div>
        <div class="gateway_nav__slider_element">
            <a href="">QWERT</a>
        </div>
        <div class="gateway_nav__slider_element">
            <a href="">QWERTY</a>
        </div>
        <div class="gateway_nav__slider_element">
            <a href="">QWER</a>
        </div>
    </div>
</div>
like image 608
Brandon Benefield Avatar asked Nov 29 '25 16:11

Brandon Benefield


1 Answers

What you can do is play with the center padding:

$('.gateway_nav').slick({
    arrows: true,
    infinite: true,
    slidesToShow: 1,
    slidesToScroll: 1,
    variableWidth: true,
    centerMode: true,
    centerPadding: '20%',
})

https://jsfiddle.net/10ftk4w2/

I don't have your CSS so I'm guessing here.

like image 68
Keith Avatar answered Dec 02 '25 07:12

Keith