How to randomize data attribute value using JS?

How can i randomize the value of a data attribute? I have a dynamic content which loops through the same div over and over again, but the value is currently hardcoded and i would like to make this dynamic.

my code:

(() => {

	let highlightBlocks = document.querySelectorAll('.highlighted-blocks__block'),
		parallaxYpos = [ "25","40","55","70","85","100"];

		[].forEach.call(highlightBlocks, (highlightBlock) => {
			let randomParallaxYpos = highlightBlock.dataset.parallaxY;
			let parallaxCurrentValue = parallaxYpos[Math.floor(Math.random() * parallaxYpos.length)];
			console.log(parallaxCurrentValue);
		});

})();

HTML:

<div class="highlighted-blocks__block" data-parallax="true" data-parallax-direction="up" data-parallax-x="0" data-parallax-y="**50** change this value?" data-parallax-easing="none" style="transform: translate3d(0px, 34.3203px, 0px);">
Content.
 </div>

From the Math.floor(Math.random() * parallaxYpos.length it looks like they already are random.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.