81 lines
2.0 KiB
HTML
81 lines
2.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>背景切换</title>
|
|
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
|
|
<style>
|
|
ul,
|
|
li,
|
|
body {
|
|
margin: 0;
|
|
padding: 0;
|
|
list-style: none;
|
|
}
|
|
|
|
ul {
|
|
overflow: hidden;
|
|
}
|
|
|
|
li {
|
|
float: left;
|
|
margin-right: 10px;
|
|
}
|
|
|
|
li img {
|
|
width: 80px;
|
|
}
|
|
|
|
body,
|
|
html,
|
|
.back {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
.back {
|
|
position: absolute;
|
|
left: 0;
|
|
top: 0;
|
|
z-index: -1;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div id="app">
|
|
<div class="back" :style="{ background: cuurenUrl }"></div>
|
|
<ul>
|
|
<li v-for="(item,index) in BackImg" :key="index">
|
|
<img :src="item.url" alt="" @click="changeUrl(index)">
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
<script>
|
|
new Vue({
|
|
el: '#app',
|
|
// 发送ajax请求
|
|
created() {
|
|
this.cuurenUrl = `url('${this.BackImg[this.currentIndex].url}')`;
|
|
},
|
|
data: {
|
|
currentIndex: 0,
|
|
cuurenUrl: '',
|
|
BackImg: [
|
|
{ title: '11', url: 'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=289489236,794389348&fm=26&gp=0.jpg' },
|
|
{ title: '222', url: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1604920693646&di=f67f827ecdb0d1905a267b08f94a782a&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201612%2F21%2F20161221112706_dfjEa.jpeg' },
|
|
]
|
|
},
|
|
methods: {
|
|
changeUrl(index) {
|
|
this.currentIndex = index;
|
|
this.cuurenUrl = `url('${this.BackImg[this.currentIndex].url}')`;
|
|
}
|
|
}
|
|
})
|
|
</script>
|
|
|
|
</html> |