使用Javascript每日横幅轮换

问题描述 投票:0回答:2

目前我使用此Banner轮换代码:

<script type="text/javascript" language="JavaScript1.2">
  var howOften = 7; //number often in seconds to rotate
  var current = 0; //start the counter at 0
  var ns6 = document.getElementById && !document.all; //detect netscape 6

  // place your images, text, etc in the array elements here
  var items = new Array();
  items[0] = "<a title='Banner 1' onclick='ga('send', 'event', 'Link', 'Banner', '.Banner 1');' href='https://www.banner1.de' target='_blank' rel='nofollow noopener'><img alt='Banner 1' src='/images/banner/Banner-1.jpg' border='0' /></a>"; //a linked image

  items[1] = "<a title='Banner 2' onclick='ga('send', 'event', 'Link', 'Banner', '.Banner 2');' href='https://www.banner2.de' target='_blank' rel='nofollow noopener'><img alt='Banner 2' src='/images/banner/Banner-2.jpg' border='0' /></a>"; //a linked image

  function rotater() {
    document.getElementById("placeholder").innerHTML = items[current];
    current = (current == items.length - 1) ? 0 : current + 1;
    setTimeout("rotater()", howOften * 1000);
  }

  function rotater() {
    if (document.layers) {
      document.placeholderlayer.document.write(items[current]);
      document.placeholderlayer.document.close();
    }
    if (ns6) document.getElementById("placeholderdiv").innerHTML = items[current]
    if (document.all)
      placeholderdiv.innerHTML = items[current];

    current = (current == items.length - 1) ? 0 : current + 1; //increment or reset
    setTimeout("rotater()", howOften * 1000);
  }
  window.onload = rotater;
</script>

是否可以重写此代码以使横幅每天轮换而不是每7秒轮换一次?

javascript rotation banner
2个回答
0
投票

你的意思是怎么说的?

第一个:var howOften = 7; //数字通常以秒为单位进行旋转

第二个还是第三个? setTimeout(“rotater()”,howOften * 1000);


0
投票

这是要旋转的秒数的变量

var howOften = 7; //number often in seconds to rotate

将其转换为1天

var howOften = 24*60*60; //number often in seconds to rotate (while the day is 24 hours 60 minutes 60 second)
© www.soinside.com 2019 - 2024. All rights reserved.