1
How could I make it so that, with every access to the site, a different video would appear? I understand that there are codes that change the background with images as below:
<script type="text/javascript">
window.onload = function(){
var imgr = Math.round(Math.random()*4);
var imgsrc = [
'imagem1.jpg',
'imagem2.jpg',
'imagem3.jpg'
];
document.getElementById('eximg').src = imgsrc[imgr];
}
</script>
<img id="eximg"/>
But how would I apply to videos?
<video playsinline="playsinline" autoplay="autoplay" muted="muted" loop="loop">
<source src="mp4/fundo.mp4" type="video/mp4">
</video>
PS: I ask that only people who understand the subject vote to close or indicate as duplicate, because one case is image and the other is video and if they do so, please give me an example, because many people who, just like me, you don’t have much experience in Jquery or Javascript and see this as differentiated cases.
Possible duplicate of Img in header changing at each page load
– hugocsl
Just a quick comment. You need to dynamically select the videos in your directory, and I remember that there is the Random method in Javascript. Think about concatenating the video name into two variables for source assignment, something like video + 1 + mp4.
– Renato Nascimento
Guys. Sorry, my strong is not Jquery. How would I apply the link example to videos? Because a case is image (background) and in mine is video. Could you give me an example?
– user24136