
<html>
<head>
<meta charset="UTF-8">
<title>轮播图</title>
<style type="text/css">
.box {
width: 500px;
height: 700px;
background-color: #efefef;
border: 1px solid lightgray;
margin: 20px auto;
text-align: center;
color: #636363;
box-shadow: 2px 2px 2px #999;
}
.box ul {
margin:0;
padding:0;
/*将ul转为BFC独立块,使之不受内部浮动元素的影响*/
overflow: hidden;
}
.box ul li {
list-style-type: none;
float:left;
background-color: skyblue;
margin-left: 55px;
}
.box ul li a {
display: block;
width: 100px;
height: 40px;
line-height: 40px;
color: white;
text-decoration: none;
}
.box ul li:hover {
font-size:1.2em;
background-color: coral;
}
.active {
font-size:1.2em;
background-color: coral;
}
.box .pic {
width: 450px;
height:450px;
border: 1px solid lightgray;
margin: 50px auto 0;
}
.box .pic img {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div class="box">
<h2>景色欣赏</h2>
<ul>
<li>
<a href="yw.jpg" title="夜晚的景色.....">夜色</a>
</li>
<li>
<a href="yw2.jpg" title="日出的景色......">日出</a>
</li>
<li>
<a href="yw3.jpg" title="小岛周边景色......">小岛</a>
</li>
</ul>
<div class="pic">
<img src="images/zwt.png" alt="" id="img">
</div>
<p id='info'></p>
</div>
<script>
var pic = document.getElementsByTagName('a');
var img = document.getElementById('img');
var p = document.getElementById('info');
for (var i = 0; i < pic.length; i++) {
pic[i].onclick = function () {
for (var i = 0; i < pic.length; i++) {
pic[i].classList.remove('active');
}
this.classList.add('active');
var picUrl = this.href;
var picInfo = this.title;
var picName = this.innerHTML;
img.src = picUrl;
p.innerHTML = '<span style="color:coral">'+picName+':'+picInfo+'</span>';
return false;
};
}
</script>
</body>
</html>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号