<!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>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
li {
list-style-type: none;
}
body {
background: url(timg2.jpg) no-repeat center top;
}
.box {
overflow: hidden;
margin: 100px auto;
box-sizing: border-box;
-webkit-box-sizing: border-box;
width: 415px;
padding: 3px 0 0 0;
background-color: #fff;
}
.box li {
float: left;
cursor: pointer;
margin-left: 3px;
}
.box img {
width: 100px;
}
</style>
</head>
<body>
<ul class="box">
<li><img src="timg2.jpg"></li>
<li><img src="timg4.jpg"></li>
<li><img src="timg7.jpg"></li>
<li><img src="timg8.jpg"></li>
</ul>
<script>
var img = document.querySelector('.box').querySelectorAll('img');
for (var i = 0; i < img.length; i++) {
img[i].onclick = function() {
document.body.style.backgroundImage = 'url(' + this.src + ')';
}
}
</script>
</body>
</html>
js-仿百度换肤
最新推荐文章于 2023-08-10 17:40:27 发布