This article is a mirror article of machine translation, please click here to jump to the original article.

View: 10493|Reply: 0

[JavaScript] Use JS to automatically change the background image of the homepage

[Copy link]
Posted on 12/23/2015 3:39:40 PM | | |
  1. var curIndex = 0;
  2.         //时间间隔 单位毫秒
  3.         var timeInterval = 1000;
  4.         var arr = new Array();
  5.         arr[0] = "/Content/images/bg/bg-1.jpg";
  6.         arr[1] = "/Content/images/bg/bg-2.jpg";
  7.         arr[2] = "/Content/images/bg/bg-3.jpg";
  8.         arr[3] = "/Content/images/bg/bg-4.jpg";
  9.         arr[4] = "/Content/images/bg/bg-5.jpg";
  10.         arr[5] = "/Content/images/bg/bg-6.jpg";
  11.         setInterval(changeImg, timeInterval);
  12.         function changeImg() {
  13.             var obj = document.getElementById("bgimg");
  14.             if (curIndex == arr.length - 1) {
  15.                 curIndex = 0;
  16.             }
  17.             else {
  18.                 curIndex += 1;
  19.             }
  20.             obj.src = arr[curIndex];
  21.         }
Copy code






Previous:C# implements Socket communication client code
Next:c# encodeURIComponent decoding
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com