Home > Web Front-end > HTML Tutorial > HTML implements background image replacement

HTML implements background image replacement

不言
Release: 2018-04-21 15:30:34
Original
7433 people have browsed it

The content of this article is about the replacement of background images in HTML. It has a certain reference value. Now I share it with you. Friends in need can refer to it.

<p class="p"> 
       <p class="p2"><img src="../img/hu.jpg"  alt=""  id="picture"></p>
       </p>
</p>

var curIndex = 0;
var timeInterval = 3000; //切换时间 3秒  可以修改
var arr = new Array();
arr[0] = "../img/hu.jpg"; //这里的是图片存放的相对路径
arr[1] = "../img/bb.jpg";
arr[2] = "../img/cc.jpg";
setInterval(changeImg, timeInterval);

function changeImg() {
var obj = document.getElementById("picture");
if(curIndex == arr.length - 1) {
curIndex = 0;
} else {
curIndex += 1;
}
obj.src = arr[curIndex];
}
Copy after login

Related Recommended:

HTML to beautify the uploaded file style

How to use HTML to implement the scrolling barrage function

HTML Implement the ticket grabbing function (set a time to open the ticket grabbing page)



The above is the detailed content of HTML implements background image replacement. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template