I'm new to writing my own jQuery and received some help with this snippet of code that works as I need it to (to animate colors, with the help of jquery-color.js plugin, and then cycle/loop through them continuously):
var c = 0;
setInterval(function () {
var colors = ['#de7056', '#4ec67f']
if (c > colors.length - 1) c = 0;
$("#neck").animate({
backgroundColor: colors[c++]
}, 1000);
}, 5000);
But now I have used this snippet multiple times to (var c1, var c2, etc.) change the color, background colour, svgFill and svgStroke (with the help of svg animate plugins) of multiple elements (#color-change1, #color-change2, etc.) and I'm wondering if there is a way to combine all of the snippets since they are all using the same transition (1000) and delay (5000)?
var c1 = 0;
setInterval(function () {
var colors = ['#de7056', '#4ec67f']
if (c1 > colors.length - 1) c1 = 0;
$("#color-change1").animate({
backgroundColor: colors[c1++]
}, 1000);
}, 5000);
var c2 = 0;
setInterval(function () {
var colors = ['#de7056', '#4ec67f']
if (c2 > colors.length - 1) c2 = 0;
$("#color-change2").animate({
svgFill: colors[c2++]
}, 1000);
}, 5000);
var c3 = 0;
setInterval(function () {
var colors = ['#536260', '#fff']
if (c3 > colors.length - 1) c3 = 0;
$("#color-change3").animate({
color: colors[c3++]
}, 1000);
}, 5000);
var c4 = 0;
setInterval(function () {
var colors = ['#536260', '#fff']
if (c4 > colors.length - 1) c4 = 0;
$("#color-change4").animate({
svgFill: colors[c4++]
}, 1000);
}, 5000);
var c5 = 0;
setInterval(function () {
var colors = ['#536260', '#fff']
if (c5 > colors.length - 1) c5 = 0;
$("#color-change5").animate({
svgStroke: colors[c5++]
}, 1000);
}, 5000);