百度换肤js

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>百度换肤</title>
<style>
* {
margin: 0;
padding: 0;
list-style: none;
}
body {
box-sizing: border-box;
padding-top: 80px;
width: 100vw;
min-height: 100vh;
background-color: gold;
background-repeat: no-repeat;
background-size: auto 100vh;
background-position: center center;
/* 背景图不滚动 */
background-attachment: fixed;
}
content {
width: 50px;
height: 2000px;
margin: 0 auto;
background-color: pink;
}
nav {
position: fixed;
top: 0;
width: 100vw;
height: 60px;
background-color: rgba(0, 0, 0, .35);
color: white;
}
nav p {
float: right;
margin-right: 50px;
height: 60px;
line-height: 60px;
font-size: 14px;
}
nav p:hover {
cursor: pointer;
}
.alert {
display: none;
align-items: center;
justify-content: center;
position: fixed;
top: 0;
z-index: 1;
width: 100vw;
height: 100vh;
background-color: rgba(0, 0, 0, .1);
}
.card {
padding: 0 20px;
display: flex;
justify-content: space-around;
align-items: center;
position: relative;
width: 920px;
height: 320px;
background-color: #fff;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 0 5px lightgray;
}
.card img:hover {
cursor: pointer;
transform: scale(1.2);
box-shadow: 0 0 3px #999;
}
.card img {
width: 180px;
height: 200px;
border-radius: 4px;
box-shadow: 0 0 3px #ccc;
transition: .3s;
}
.card .close {
position: absolute;
right: 30px;
top: 30px;
font-size: 20px;
color: lightgray;
}
.close:hover,
.no:hover {
cursor: pointer;
color: cornflowerblue;
}
.no {
position: absolute;
bottom: 0;
width: 100%;
height: 40px;
line-height: 40px;
font-size: 14px;
text-align: center;
color: lightgray;
}
.checked {
outline: 4px solid tomato;
}
</style>
</head>
<body>
<nav>
<p>更换皮肤</p>
</nav>
<div class="alert">
<div class="card">
<span class="close">X</span>
<span class="no">不使用皮肤</span>
<img src="./img/xiu1.jpg" alt="">
<img src="./img/xiu5.jpg" alt="">
<img src="./img/xiu7.jpg" alt="">
<img src="./img/xiu9.jpg" alt="">
<img src="./img/xiu4.jpg" alt="">
</div>
</div>
<div class="content"></div>
</body>
<script>
var dAlert = document.querySelector('.alert');
var p = document.querySelector('nav p');
var spanClose = document.querySelector('.close');
var imgs = document.querySelectorAll('img');
var body = document.querySelector('body');
var pNo = document.querySelector('.no');
// 当前显示图片的下标,如果为-1,则代表没有被选中;
var index = -1;
p.onclick = function () {
dAlert.style.display = 'flex';
}
spanClose.onclick = function () {
dAlert.style.display = 'none';
}
for (i = 0; i < imgs.length; i++) {
imgs[i].xiabiao = i;
imgs[i].onclick = function () {
if (index === this.xiabiao) {
return;
}
// this 指向函数的拥有者
body.style.backgroundImage = `url(${this.src})`;
// 1.暴力解除
// for (var j = 0; j < imgs.length; j++) {
// imgs[j].className = "";
// }
// 2.下标
if (index != -1) {
imgs[index].className = '';
}
this.className = 'checked';
index = this.xiabiao;
}
}
pNo.onclick = function () {
body.style.backgroundImage = '';
imgs[index].className = '';
index = -1;
}
</script>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值