Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
21
rated 0 times [  22] [ 1]  / answers: 1 / hits: 30941  / 7 Years ago, tue, february 7, 2017, 12:00:00

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? :)


More From » jquery

 Answers
14

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]);
});

[#59049] Friday, February 3, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aileent

Total Points: 556
Total Questions: 107
Total Answers: 101

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
;