博客列表 >实现简单轮播效果

实现简单轮播效果

奔跑的博客
奔跑的博客原创
2019年04月04日 08:25:34609浏览

<!DOCTYPE html>

<html lang="en">


<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>轮播图</title>

<style>

div {

width: 500px;

height: 300px;

margin: 50px auto;

overflow: hidden;

position: relative;


}


img {

width: 500px;

height: 300px;

}


p {

color: black;

width: 500px;

height: 30px;

position: absolute;

z-index: 1000;

top: 240px;

text-align: center;

line-height: 30px;

}


p span {

display: inline-block;

width: 20px;

height: 20px;

text-align: center;

background: rgba(254, 254, 254, 0.6);

border-radius: 50%;

line-height: 20px;

cursor: pointer;

}

</style>

</head>


<body>


<div id="photo">

<a href=""><img src="static/images/1.jpg" alt=""></a>

<a href=""><img src="static/images/2.jpg" alt=""></a>

<a href=""><img src="static/images/3.jpg" alt=""></a>

<a href=""><img src="static/images/4.jpg" alt=""></a>

<a href=""><img src="static/images/5.jpg" alt=""></a>

<p>

<span onclick="change(0)">1</span>

<span onclick="change(1)">2</span>

<span onclick="change(2)">3</span>

<span onclick="change(3)">4</span>

<span onclick="change(4)">5</span>

</p>

</div>


<script>

function change(num) {

var obj = document.getElementById('photo');

var obj_a = obj.getElementsByTagName('a');

for (var i = 0; i < obj_a.length; i++) {

obj_a[i].style.display = 'none';

}

obj_a[num].style.display = 'block';

}

</script>


</body>


</html>


声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议