question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Target the previous and next slide for css-styling ?

See original GitHub issue

Is it possible to speak via css with previous and next slide? I found slickCurrentSlide(); but i couldn’t handle it to set new classes to the previous and next slide. Do you have a quick hint for me?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5

github_iconTop GitHub Comments

4reactions
Serifenloscommented, Jun 23, 2014

I could solve this for me:

$('.slider').slick({
    centerMode: true,
    centerPadding: '5%',
    slidesToShow: 1,

    onInit: function () {
        $('.slick-active').prev().addClass('prev');
        $('.slick-active').next().addClass('next');
    },

    onBeforeChange: function () {
        $('.slick-slide').removeClass('prev next');
    },

    onAfterChange: function () {
        $('.slick-active').prev().addClass('prev');
        $('.slick-active').next().addClass('next');
    }

});
2reactions
Serifenloscommented, Oct 2, 2018

For a redesign of the website i was looking for a new solution. I found this and get happy: https://stackoverflow.com/a/32532363

$('.slider')
.on('afterChange init', function(event, slick, direction){
    // console.log('afterChange/init', event, slick, slick.$slides);
    // remove all prev/next
    slick.$slides.removeClass('prevSlide').removeClass('nextSlide');

    // find current slide
    for (var i = 0; i < slick.$slides.length; i++)
    {
        var $slide = $(slick.$slides[i]);
        if ($slide.hasClass('slick-current')) {
            // update DOM siblings
            $slide.prev().addClass('prevSlide');
            $slide.next().addClass('nextSlide');
            break;
        }
    }
  }
)
.on('beforeChange', function(event, slick) {
    // optional, but cleaner maybe
    // remove all prev/next
    slick.$slides.removeClass('prevSlide').removeClass('nextSlide');
})
.slick({
  speed: 900,
  cssEase: "cubic-bezier(0.165, 0.840, 0.440, 1.000)",
  centerMode: !0,
  centerPadding: "4%",
  lazyLoad: "progressive",
  slidesToShow: 1
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Implement a CSS-only slideshow / carousel with next and ...
Now we need to affect all the slides that slip into the past. I have a avoided mentioning the :target pseudo-class prior to...
Read more >
Sample Center Slide Panel - CSS styling issue - Logi Analytics
I'm not great with CSS, i've tried creating a class that targets the AG that sets the ::after and ::before content to none....
Read more >
How to Create a Stylish Image Content Slider in Pure CSS3
Step 1 – HTML · Step 2 – Basic CSS Styling · Step 3 – CSS3 Styling · Step 6 – “Not Target”...
Read more >
Advanced form styling - Learn web development | MDN
In this article, we will see what can be done with CSS to style the types of form control that are more difficult...
Read more >
Upgraded fading slideshow < CSS - The Art of Web
This is a rewrite of our previous Fading slideshow with a touch of JavaScript script making it easier to use and taking advantage...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found