<body>
<!-- 베너영역 -->
<div id="banner">
<a href="#" id="banner-link" target="_blank">
<img src="" id="banner-img" width="320" />
</a>
</div>
<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>
<script>
let banner = [
{ img:'img/captainamerica.png', url:'https://www.naver.com' },
{ img:'img/batman.png', url:'https://www.google.com' },
{ img:'img/ironman.png', url:'https://www.daum.net' },
{ img:'img/thor.png', url:'https://www.google.com' }
];
$(function(){
random_banner();
setInterval(function(){
random_banner();
},1000);
});
function random_banner(){
let rand = random(0, banner.length-1);
let item = banner[rand];
$('#banner-img').attr('src',item.img);
$('#banner-link').attr('href',item.url);
}
function random(n1, n2){
return parseInt(Math.random() * (n2 - n1 + 1)) + n1;
}
</script>
</body>