Preface: I am new to writing my own jQuery code and have had help writing the animateContinously() function below.
I'm using backstretch.js to have a full browser viewport/background slideshow and jQuery animate() function to change the color (with the help of the jquery-color.js plugin) of the text that shows on top of the backstretch controlled images, depending on which backstretch image is showing. It works, but the backstretch() duration and animate() delay are out of sync if I set them to the same number, ie: 5000 (5 seconds). So I tried offsetting them by 1000 (1 second) and the text and backstretch images fade-in/out at the exact same time, as desired...but after 15 or so transitions they fall out of sync again.
Any ideas/help as to why the same duration & delay time amount doesn't work? And/or why the 1 second offset works at first and then falls out of sync? Here is my code:
<script src="jquery.js"></script>
<script src="jquery-color.js"></script>
<script src="backstretch.js"></script>
<script>
$.backstretch([
"_img/bg01.jpg",
"_img/bg02.jpg"
], {
fade: 1000,
duration: 4000
});
</script>
<script>
function animateContinuously($element, attr, values) {
var i = 0, count = values.length;
setInterval(function() {
i = (i + 1) % count;
var props = {};
props[attr] = values[i];
$element.animate(props, 1000);
}, 5000); // // in sync with backstretch() if 1000 more, but falls out of sync after 15-18 transitions
animateContinuously($("#color-change1"), 'color', ['#de7056', '#4ec67f']);
animateContinuously($("#color-change2"), 'svgFill', ['#de7056', '#4ec67f']);
</script>
</body>