본문 바로가기
HTML

html 이미지 5초마다 바꾸기

by 준섭이 2023. 12. 28.
728x90

### html 내에서 img 5초마다 전환

<html>
<head>
 <title>hi</title>
 <script type="text/javascript">
  var imgArray=new Array();
  imgArray[0]="1.jpg";
  imgArray[1]="2.jpg";
  imgArray[2]="3.jpg";
  imgArray[3]="4.jpg";

  function showImage(){
   var imgNum=Math.round(Math.random()*3);
   var objImg=document.getElementById("introimg");
   objImg.src=imgArray[imgNum];
   setTimeout(showImage,5000);
  }

 </script>
</head>
<body onload="showImage()">
 <img id="introimg" border="0">
</body>
</html>