最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Getting data-attributes from slides in slick carousel - Stack Overflow

programmeradmin1浏览0评论

After the 1.4 update to Slick carousel, the method to pull data attributes from the current slide changed.

The previous method which worked:

onAfterChange: function(slide, index) {
   $('.project-caption').find('p').replaceWith("<p>" + $(slide.$slides.get(index)).data('description') + "</p>");
}

Now the documentation says to call current slide after change like this:

$('.your-element').on('afterChange', function(event, slick, currentSlide, nextSlide){
    console.log(nextSlide);
});`

I've tried everything I know to get the data attribute using the new method.

Author show me how to get the current Slide as an integer here: /

But does anyone know how to get the current slide data-attributes?

After the 1.4 update to Slick carousel, the method to pull data attributes from the current slide changed.

The previous method which worked:

onAfterChange: function(slide, index) {
   $('.project-caption').find('p').replaceWith("<p>" + $(slide.$slides.get(index)).data('description') + "</p>");
}

Now the documentation says to call current slide after change like this:

$('.your-element').on('afterChange', function(event, slick, currentSlide, nextSlide){
    console.log(nextSlide);
});`

I've tried everything I know to get the data attribute using the new method.

Author show me how to get the current Slide as an integer here: http://jsfiddle/3b4kqy9p/

But does anyone know how to get the current slide data-attributes?

Share Improve this question edited Jul 24, 2015 at 3:05 JasonMArcher 15k22 gold badges59 silver badges53 bronze badges asked Feb 16, 2015 at 16:38 Tom Eberhardt-SmithTom Eberhardt-Smith 1101 gold badge2 silver badges13 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

You can access the $slides array from the slick object:

var elSlide = $(slick.$slides[currentSlide]);
var materials = elSlide.data('materials');

I have updated the jsfiddle here

Inside your event handler put:

var activeSlide = $('#carousel').find('.slick-active');
var year = activeSlide.data('year');

this works based on the class changing made by the plugin.

发布评论

评论列表(0)

  1. 暂无评论