admin管理员组文章数量:1289739
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 - /
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/q5yae1t3/9/
Share Improve this question asked Jun 9, 2015 at 18:01 HlibHlib 631 gold badge1 silver badge5 bronze badges2 Answers
Reset to default 7You 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/q5yae1t3/19/ Hope that helps!
This is a one-liner.
var currentSlide = $('.slideshow').slick('slickCurrentSlide');
$('.slideshow').slick('slickRemove', currentSlide);
本文标签: javascriptSlickjs How to remove current slideStack Overflow
版权声明:本文标题:javascript - Slick.js: How to remove current slide? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741482656a2381254.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论