Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slick.js: How to remove current slide?

Using Slick.js - how i can remove current active slide? I made of an example, but nothing works

var $status = $('.pagingInfo');
var $slickElement = $('.slideshow');

$slickElement.on('init reInit afterChange', function (event, slick, currentSlide, nextSlide) {
    //currentSlide is undefined on init -- set it to 0 in this case (currentSlide is 0 based)
    var i = (currentSlide ? currentSlide : 0) + 1;
    $status.text(i + '/' + slick.slideCount);
});

$slickElement.slick({
    slide: 'img',
    speed: 1,
    infinite: false,
    swipe: false,
    autoplay: false,
    dots: false
});

$('.remove-slide').on('click', function() {
    $slickElement.slick('slickRemove', i);
});

My fiddle here - http://jsfiddle.net/q5yae1t3/9/

like image 380
Hlib Avatar asked Apr 16 '26 22:04

Hlib


1 Answers

You don't have an i variable set in the $(...).on(...) function. You need to set i in order to remove something based on i. Then you also need to change all the data-slick-index attributes, because those weren't changed when the slide counter gets changed.

$('.remove-slide').on('click', function() {
   i = $("img.slick-active").attr("data-slick-index");
   $slickElement.slick('slickRemove', i);
   var j = 0;
   $("img.slick-slide").each(function(){
     $(this).attr("data-slick-index",j);
     j++;
   });
});

http://jsfiddle.net/q5yae1t3/19/ Hope that helps!

like image 80
RoboticRenaissance Avatar answered Apr 18 '26 12:04

RoboticRenaissance



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!