본문 바로가기

js

[js]메인슬라이드 랜덤 출력

<div id="mainSlider">
	<video src="images/mainSlider.mp4" loop autoplay muted></video>
</div>

<script>
function random_ms() {
  let mainSlider = new Array();
  		mainSlider[0] = "mainSlider01";
  		mainSlider[1] = "mainSlider02";
  		mainSlider[2] = "mainSlider03";
  
  let link="images/";
  let mp4=".mp4";

  let random = Math.floor( Math.random() * (mainSlider.length) );


 $("#mainSlider video").attr("src",link+mainSlider[random]+mp4);

 }

 random_ms()
 </script>

img일경우 let mp4 변경


top