这个Banner唯一不好的就是没有前进和后退的button,写过两个版本的banner,这次这个是下面有浮动层的。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body style="padding: 0; margin: 0;">
<div style="width: 1024px; margin: auto;">
<div id="can" style="width: 820px; height: 421px;">
<img src="img/qingxin_ziran_fengjing-001.jpg" id="img" />
</div>
<div style="position: absolute; left: 500px; top: 420px; opacity: 0.5;">
<input type="radio" id="vary" value="first" name="start" checked="checked" />
<input type="radio" id="very" value="second" name="start" />
<input type="radio" id="vory" value="thrid" name="start" />
<input type="radio" id="vbry" value="fouth" name="start" />
<input type="radio" id="vcry" value="fifth" name="start" />
</div>
</div>
<script>
var index = 0, start;
var img1 = document.getElementById("img");
var imgs = ["img/qingxin_ziran_fengjing-001.jpg", "img/qingxin_ziran_fengjing-005.jpg", "img/qingxin_ziran_fengjing-007.jpg", "img/qingxin_ziran_fengjing-008.jpg", "img/qingxin_ziran_fengjing.jpg"];
var get = function () {
clearInterval(start);
start = setInterval(fun, 5000);
};
var arr = document.getElementsByTagName('input');
for (var i = 0; i < arr.length; i++) {
arr[i].index = i;
arr[i].onmousemove = function () {
clearInterval(start);
this.checked = true;
index = this.index;
img1.src = imgs[index];
};
arr[i].onmouseout = function () {
get();
};
}
function fun() {
index++;
arr[index % 5].checked = true;
img1.src = imgs[index % 5];
}
get();
</script>
</body>
</html>
这个banner是带button的,但没有浮动层。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="js/jquery.js"></script>
<title></title>
</head>
<body>
<div>
<input type="button" style="width:20px;height:40px;" onclick="play('<')" value="<" id="div1" />
<input type="button" style="margin-left: 670px;width:20px;height:40px;position:relative;"onclick="play('>')" value=">" id="div2" />
<img id="img1" src="img/timg.jpg" />
</div>
<script>
var index = 0;
function play(val) {
if (val == "<") {
var img1 = document.getElementById("img1");
var imgs = ["img/timg.jpg", "img/timg1.jpg", "img/timg2.jpg", "img/timg3.jpg", "img/timg4.jpg"];
index--;
if (index == -1) {
index = 4;
}
img1.src = imgs[index];
} else {
var img1 = document.getElementById("img1");
var imgs = ["img/timg.jpg", "img/timg1.jpg", "img/timg2.jpg", "img/timg3.jpg", "img/timg4.jpg"];
index++;
if (index == imgs.length) {
index = 0;
}
img1.src = imgs[index];
}
}
setInterval(play, 5000);
</script>
</body>
</html>
来源:https://www.cnblogs.com/peace-ful/p/6902099.html