chrisj
7/8/2019 - 1:55 PM

Generate an Array of Selectors

/* --------------------------
* VARIABLES
* -------------------------- */

let contentHeroText = document.querySelector('.content-hero-text');

function init() {
	
	if (!contentHeroText) {
    return;
  }
  
  
  /* --------------------------
	 * GENERATE AN ARRAY OF ALL ITEMS
	 * -------------------------- */
  
  const contentHeroTextAll = Array.from(document.querySelectorAll('.content-hero-text'));
  
  
  /* --------------------------
	 * LOOP THROUGH ALL HERO IMAGES
	 * -------------------------- */
	 
  contentHeroTextAll.forEach(((heroText) => {
		const heroTextHeadline = heroText.querySelector('.content-hero-text__headline');
		const heroTextArrow = heroText.querySelector('.content-hero-text__arrow-vertical');
	  
	  // Generate a random Position
	  let randomPosition = randomWholeNumber(15, 85);
	  	  
	  // Reset the Arrow Position Randomly
	  heroTextArrow.style.left = randomPosition + '%';
	  
	}));
	
	
	/* --------------------------
	 * RETURN RANDOM WHOLE NUMBER
	 * -------------------------- */
	 
	function randomWholeNumber(min, max){
	  return Math.floor(Math.random() * (1 + max - min) + min);
	}
  
}

export default {
  init,
};