Vue文件纯JS实现多列轮播图
最终效果是这样:
代码:
<template>
<div class="total">
<div class="back_add">
<div class="threeImg">
<div class="Containt">
<div class="iconleft" @click="zuohua">
<i class="el-icon-arrow-left"></i>
</div>
<ul
class="uls"
:style="{ left: calleft + 'px' }"
v-on:mouseover="stopmove()"
v-on:mouseout="move()"
>
<li v-for="(item, index) in superurl" :key="index">
<img :src="item.img" />
</li>
</ul>
<div class="iconright" @click="youhua">
<i class="el-icon-arrow-right"></i>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: "Dashboard",
data() {
return {
superurl: [
{
url: "",
img: require("../../assets/image/banner1.jpg"),
},
{
url: "",
img: require("../../assets/image/banner2.jpg"),
},
{
url: "",
img: require("../../assets/image/banner3.jpg"),
},
{
url: "",
img: require("../../assets/image/banner1.jpg"),
},
{
url: "",
img: require("../../assets/image/banner2.jpg"),
},
{
url: "",
img: require("../../assets/image/banner3.jpg"),
},
],
calleft: -18,
};
},
created() {
this.move();
},
methods: {
//移动
move() {
// this.timer = setInterval(this.starmove, 2500);
},
//开始移动
starmove() {
this.calleft -= 330;
if (this.calleft < -1020) {
this.calleft = -18;
}
},
//鼠标悬停时停止移动
stopmove() {
clearInterval(this.timer);
},
//点击按钮左移
zuohua() {
clearInterval(this.timer);
this.calleft -= 330;
if (this.calleft < -1020) {
this.calleft = -18;
}
},
//点击按钮右移
youhua() {
clearInterval(this.timer);
this.calleft += 330;
if (this.calleft > 0) {
this.calleft = -1008;
}
},
},
};
</script>
<style lang="scss" scoped>
#divAdd {
background-color: #ededed;
/*width: 100%;*/
/*min-width: 1200px;*/
width: 1000px;
margin: 0px auto;
}
.divAdd-con {
margin: 0px auto;
width: 1000px;
overflow: auto;
padding: 30px 0px;
}
.divAdd-con img {
float: left;
}
.indexrt {
margin: 0px 40px;
}
.divAddleft img {
float: left;
margin-bottom: 7px;
}
.divAddleft {
float: left;
display: inline;
width: 370px;
}
.divAddrt {
float: right;
display: inline;
margin-top: 7px;
}
.back_add {
width: 750px;
background-color: #ededed;
}
.divAdd-con img {
border: none;
}
a:focus,
a:hover {
color: #23527c;
}
.threeImg {
height: 145px;
background: #ededed;
// border-bottom: 3px solid #4679b2;
min-width: 1010px;
}
.threeImg .Containt ul {
margin: 0 auto;
// padding: 0 97px;
width: 2400px;
position: absolute;
left: 0px;
cursor: pointer;
height: 100%;
}
.threeImg .Containt ul li {
width: 300px;
margin-right: 30px;
margin-top: 10px;
float: left;
}
.threeImg .Containt ul li img {
height: 128px;
width: 100%;
}
.Containt {
position: relative;
width: 1010px;
height: 130px;
// overflow-x: auto;
overflow: hidden;
margin: 0 auto;
// background-color: red;
}
.iconleft {
position: absolute;
width: 20px;
height: 80px;
top: 30px;
left: 10px;
z-index: 99999;
padding-top: 37px;
background-color: #ddd;
vertical-align: middle;
}
.iconright {
position: relative;
left: 977px;
top: 70px;
background-color: #ddd;
/*position: absolute;*/
width: 20px;
height: 80px;
top: 30px;
z-index: 99999;
padding-top: 37px;
background-color: #ddd;
vertical-align: middle;
}
.uls {
margin: 0 50px;
}
.total {
width: 80%;
// transform: scale(0.9);
// float: left;
}
</style>

浙公网安备 33010602011771号