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

javascript - slick.js CSS change on slide change - Stack Overflow

programmeradmin0浏览0评论

Is it possible to change css for a div on slick.js slider change? Basically if the slider autoplays or from button click I'd like to cycle through an array of colors and set the background color of .content to that color. Am I being too crazy?

var colors = ['#576986', '#D0D5D6', '#DFDEE5'];

$('.content').css({'background': current i++});

Check out the demo jsfiddle

Any ideas? :)

Is it possible to change css for a div on slick.js slider change? Basically if the slider autoplays or from button click I'd like to cycle through an array of colors and set the background color of .content to that color. Am I being too crazy?

var colors = ['#576986', '#D0D5D6', '#DFDEE5'];

$('.content').css({'background': current i++});

Check out the demo jsfiddle

Any ideas? :)

Share Improve this question asked Feb 7, 2017 at 4:47 meow-meow-meowmeow-meow-meow 5182 gold badges10 silver badges26 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 13

Slick has events, you can find the full list here: https://github.com/kenwheeler/slick

$(".slider").on("beforeChange", function (){
    //change color here
})

To cycle through colors:

var colors = ["red", "orange", "yellow", "green", "blue"];
var currentIndex = 0;

$(".slider").on("beforeChange", function (){
    $(".content").css("background-color", colors[currentIndex++%colors.length]);
});
发布评论

评论列表(0)

  1. 暂无评论