首页 > 其他分享 >vue实现上下切换自动轮播 移入移出暂停轮播

vue实现上下切换自动轮播 移入移出暂停轮播

时间:2022-11-13 21:46:22浏览次数:46  
标签:vue 轮播 url 移出 imgIndex color getMove let

<template>
  <div class="about">
    <div style="display:flex;">
      <div class="left">
        <div class="box1">
          <div class="box2" :style="{ backgroundColor: bgC }"  @mouseover="yiru(imgIndex)" @mouseleave="yichu">{{imslist[imgIndex].url }}</div>
        </div>
      </div>
      <div class="right">
        <div v-for="(item, index) in imslist" style="height:50px;width:200px;" :key="index" @mouseover="yiru(index)"
          @mouseleave="yichu">
          <div :class="index == imgIndex?'newstyle':'oldstyle'">{{ item.url}}</div>
        </div>
      </div>

    </div>
  </div>
</template>

  

<script>

export default {
  name: 'AvoutView',
  data() {
    return {
      imslist: [
        { url: '111', },
        { url: '222', },
        { url: '333', },
        { url: '444', },
      ],
      imgIndex: 0,
      bgC: '#000',
    }
  },
  mounted() {
    this.getMove()
  },
  methods: {

    getMove() {
       let timer= setInterval(() => {
          if(this.imgIndex<3){
            this.imgIndex++
          }else{
            clearInterval(timer)
            setTimeout(()=>{
              this.imgIndex=0
              this.getMove()
            },100)
          }
        }, 1000)
    },

    yiru(index) {
      this.imgIndex = index
      let endTime = setInterval(function () { }, 10000);
      for (let i = 1; i <= endTime; i++) {
        clearInterval(i)
      }
    },
    
    yichu() {
      this.getMove()
    }

  }

}
</script>

  

<style lang="less">
.box1 {
  height: 200px;
  width: 200px;
  color: #fff;
}

.box2 {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
}

.newstyle{

  border: 1px solid blue;
  background-color: #ccc;

}


</style>

  

 

标签:vue,轮播,url,移出,imgIndex,color,getMove,let
From: https://www.cnblogs.com/zyzlb/p/16887054.html

相关文章

  • sh: vue-cli-service: command not found
    mac环境下运行vue项目报错sh:vue-cli-service:commandnotfound解决方法:cd到项目目录下,执行命令sudorm-rfnode_modulespackage-lock.json&&npminstall然后根......
  • 47.vue-router的钩子函数
    钩子函数就是路由导航守卫;有7个守卫,分为3类;全局守卫:在全部的组件生效;beforeEach全局前置守卫afterEach全局后置守卫 解析守卫......
  • 初识Vue
    一、什么是Vue简单的说,Vue是一个用来开发Web界面的前端库,就是一个叫vue.js的文件,就好比jQuery库的jquery.js。但Vue远不止这些,vue周边还发展了很多其他的工具,也都是一堆j......
  • 46.使用过vuex和vue-router吗
    使用过,vuex是状态管理工具,它的数据可以被所有的组件获取,方法可以被所有的组件调用;vuex 的内部的运行机制:state提供了数据驱动视图,dispath派发actions执行异步操作,comm......
  • 组件之间的通信2-->vuex状态管理
    在上期,我们讲了父子组件的传递方式,但是,如果我们想知道这些数据从哪里来的话,就需要一层一层找父组件,最后才能找到数据,容易造成Prop逐级透传问题今天,我们将介绍另一......
  • 【Vue2-04】scoped样式
    scoped样式作用:让样式在局部生效,防止冲突写法:<stylescoped><template><div></div></template><script>exportdefault{}</script......
  • 【Vue2-02】ref属性
    ref属性被用来给元素或子组件注册引用信息(id的替代者)应用在html标签上获取的是真实DOM元素,应用在组件标签上是组件实例对象(vc)使用方式:打标识:<h1ref="xxx">...</......
  • 【Vue2-03】props属性
    props配置功能:让组件接收外部传过来的数据数据传递:<Demoname="xxx">接收数据:方式一(只接收): props:['name'] 方式二(限制类型): props:{ name:String......
  • 35. vue响应式的get和set如何触发或者过程
    首先,vue内部使用 Object.defineProperty给data中的数据添加了getter和setter函数 ;当我们访问数据的时候,会触发getter函数return给我们数据值,当我们修改数据......
  • 34.vue响应式
    响应式就是数据发生变化,ui界面自动更新内容;vue响应式的实现是在创建vue实例的时候,遍历data数据,通过Object.defineProperty给每个数据添加getter和setter函数,获取......