Vue简易轮播图

 图片定时轮播,左右换页,下标显示

vue简易轮播图

<script setup>
import { reactive, ref } from 'vue';
// 图片数据
let imgs = reactive([
  'src/assets/images/轮播图1.jpg',
  'src/assets/images/轮播图2.jpg',
  'src/assets/images/轮播图3.jpg',
  'src/assets/images/轮播图4.jpg',
  'src/assets/images/轮播图5.jpg'
])
// 定义初始序号
let timeIndex = ref(0)


//定时器
setInterval(function () {

  timeIndex.value++
  if (timeIndex.value == imgs.length) {
    timeIndex.value = 0
  }
  console.log(timeIndex)
}, 3000)


// 加1
let add = function () {

  this.timeIndex--
  if (this.timeIndex <= 0) {
    this.timeIndex = 4
  }
  console.log(timeIndex)
}
// 减一
let pre = function () {
  this.timeIndex++
  if (this.timeIndex >= 5) {
    this.timeIndex = 0
  }

  console.log(timeIndex)
}



let Bgcolor = ref("red")



</script>
<template>
  <div class="img_nav">
    <p :style="index == timeIndex ? { backgroundColor: Bgcolor } : { backgroundColor: 'rgb(206, 206, 206)' }"
      v-for="(item, index) in imgs.length  ">
    </p>

  </div>
  <div class="abc">
    <img :src="imgs[timeIndex]" alt="没有">
  </div>
  <div class="yuan">
    <div @click="add">&lt;</div>
    <div @click="pre">&gt;</div>
  </div>
</template>
<style scoped>
.img_nav {
  position: absolute;
  top: 350px;
  left: 400px;
}

.img_nav p {
  float: left;
  width: 30px;
  height: 5px;
  background-color: rgb(206, 206, 206);
  margin-left: 5px;
}

img {
  width: 950px;

}

.abc {
  overflow: hidden;
  height: 400px;
  width: 950px;
}

.yuan div {
  width: 40px;
  height: 40px;
  background-color: rgb(255, 255, 255, 0.6);
  border-radius: 50%;
  float: left;
  position: absolute;
  top: 180px;
  left: 20px;
  cursor: pointer;
  text-align: center;
  font-size: 26px;
  color: rgb(199, 0, 0);
}

.yuan div:hover {
  background-color: rgb(180, 188, 188, 0.6);
}

.yuan div:last-child {
  margin-left: 890px;
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值