I'm working with Animate on Scroll and want to assign a different animation delay to random elements in an array (or even vs. odd), which are displayed as list items. Since you have to add/change the data attribute (e.g. data-aos-delay="50"), I'm not sure how best to do this so that half the list items have a different delay time. Thanks so much!
var words = ["Superheroes", "supervillains", "aliens", "monsters", "wizards", "warriors", "witches", "barbarians", "creatures", "robots", "cyborgs", "droids", "time travelers", "spaceships", "star fighters "]
function wordsLoad() {
// Shuffle function from http://stackoverflow.com/a/2450976
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
while (currentIndex !== 0) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
words = shuffle(words);
//create HTML for each word
function createWord(word) {
return '<li class="text-uppercase" data-aos="slide-up">' + word + '</li>';
}
//add words HTML to page
function generateWords() {
const group = document.querySelector('.products');//.products of class of <ul>
const wordHTML = words.map(function(word) {
return createWord(word);
});
group.innerHTML = wordHTML.join('');
}
generateWords();
}
$(document).ready(function() {
wordsLoad();
});
<li class="text-uppercase" data-aos="slide-up">you want to add an attributedata-aos-delaywith a random number?data-aos-delayto all elements, but every other with a different number such as<li class="text-uppercase" data-aos="slide-up" data-aos-delay="50">star fighters </li> <li class="text-uppercase" data-aos="slide-up" data-aos-delay="100">aliens</li> <li class="text-uppercase" data-aos="slide-up" data-aos-delay="50">warriors</li>...