jeudi 7 avril 2022

Random background video on page load with html/js

Is worked my way through all responses but i just can't get my head around how to make this work. I want to have a selection of 4 background videos which random on load. So far, this is what i got.

const possibleVideos = ["/_1/video/bgvid3.mp4", "/_1/video/bgvid2.mp4"];
const randomVideo = possibleVideos[Math.floor(Math.random() * possibleVideos.length)];
document.querySelector('video.background-video').src = randomVideo;
<video id="background-video" disablepictureinpicture controlslist="nodownload" autoplay loop muted poster="">
        <source src="/_1/video/bgvid3.mp4" type="video/mp4">
</video>

I understand how the parts work but i dont understand how to connect them.




Aucun commentaire:

Enregistrer un commentaire