Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
187
rated 0 times [  194] [ 7]  / answers: 1 / hits: 20732  / 6 Years ago, mon, may 14, 2018, 12:00:00

I am trying to add functionality to slick slider where when you click on a slide it will remove it from the slider.



I looked at the documentation on Slick Sliders website and it shows how to add/remove slides, but that only works for the last slide in the slider.



I am trying to make it work so you can remove a specific slide based on which one is clicked.



<div class=slider add-remove slick-initialized slick-slider>
<div aria-live=polite class=slick-list draggable>
<div class=slick-track style=opacity: 1; width: 80px; transform: translate3d(0px, 0px, 0px); role=listbox>
<div class=slick-slide slick-current slick-active data-slick-index=0 aria-hidden=false style=width: 80px; tabindex=-1 role=option aria-describedby=slick-slide100>
<h3>1</h3>
</div>
</div>
</div>
</div>

<a href=javascript:void(0) class=button js-remove-slide>Remove Slide</a>


$('.js-remove-slide').on('click', function() {
$('.add-remove').slick('slickRemove',slideIndex - 1);
if (slideIndex !== 0){
slideIndex--;
}
});


EDIT: I added some more code to show how it is set up for Slick slider HERE this is set up to remove the last slide in the slider.



I'm trying to set it up so when the remove button is clicked on a slide that slide will be removed from the slider. The snippet I grabbed from the Slick Slider website only removes the last slide in the slider. So I'm trying to figure out how to remove a specific slide on click.



image


More From » jquery

 Answers
148

Here is a CodePen with your solution




console.clear();

$('.slider').slick({
dots: true
});

$('.slide').on('click', function() {
$('.slider').slick('slickRemove', $('.slick-slide').index(this) - 1);
});

html,
body {
background: #102131;
text-align: center;
}

.slider {
width: 400px;
margin: 20px auto;
padding: 20px;
color: white;
}

.slider img {
display: block;
margin: auto;
}

<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>
<script src=//cdn.jsdelivr.net/jquery.slick/1.5.5/slick.min.js></script>

<link rel=stylesheet href=https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.css>
<link rel=stylesheet href=https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick-theme.min.css>

<div class=slider>
<div class=slide>
<img src=http://fillmurray.com/300/300 alt= class=img-responsive />
<h1>slide 1</h1>
</div>
<div class=slide>
<img src=http://fillmurray.com/300/300 alt= class=img-responsive />
<h1>slide 2</h1>
</div>
<div class=slide>
<img src=http://fillmurray.com/300/300 alt= class=img-responsive />
<h1>slide 3</h1>
</div>
<div class=slide>
<img src=http://fillmurray.com/300/300 alt= class=img-responsive />
<h1>slide 4</h1>
</div>
<div class=slide>
<img src=http://fillmurray.com/300/300 alt= class=img-responsive />
<h1>slide 5</h1>
</div>
</div>




[#54433] Friday, May 11, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kadinl

Total Points: 321
Total Questions: 117
Total Answers: 103

Location: Nepal
Member since Mon, Jan 4, 2021
3 Years ago
;