左右点击滚动

<template>
  <div>
    <div>
      <el-button @click="lunBoDia = false">关闭轮播</el-button>
      <div>
        <el-button @click="btnClick(-1)"></el-button>
      </div>
      <div>
        <el-button @click="btnClick(1)"></el-button>
      </div>
    </div>
    <div class="hello">
      <div class="div1" ref="div1Ref" id="asd">
        <div ref="scrolla">
          <div class="item1Div" @click="item1Click(item, index)" :class="{ active: index == curIndex }" v-for="(item, index) in arr1" :ref="'left' + index" :key="index + '22'">{{ item.name }}</div>
        </div>
      </div>

      <div class="div2">
        <div class="youMainDiv">
          <div class="rightDiv">
            <div @click="item2Click(item2, index2)" :class="{ active2: index2 == curIndex }" v-for="(item2, index2) in arr1" :key="item2.name">
              <el-image style="width: 100px; height: 100px; margin-left: 10px" :src="item2.name" fit="cover"></el-image>
            </div>
          </div>
        </div>

        <div class="lunBoDiv" v-show="lunBoDia && arr1.length">
          <el-image style="width: 100px; height: 100px" :src="arr1[curIndex].name"></el-image>
          <div>{{ arr1[curIndex].name }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
/* eslint-disable */
export default {
  name: 'HelloWorld',
  props: {
    msg: String,
  },
  data() {
    return {
      curIndex: 0,
      lunBoDia: false,
      arr1: [],
      imagePath: '',
    };
  },
  created() {
    for (let index = 0; index < 3; index++) {
      let obj = { name: index + '.png', type: 1 };
      this.arr1.push(obj);
    }
  },
  mounted() {},
  methods: {
    item1Click(item, index) {
      this.curIndex = index;
    
    },
    leftScrollHandler() {
      const ceilHeight = 22;
      const curRef = 'left' + this.curIndex;
      const domRef = this.$refs[curRef][0];

      let parTop = this.$refs.div1Ref.offsetTop;
      let curTop = domRef.offsetTop;
      let cha = curTop - parTop + ceilHeight;
      let scrollHeight = cha - 300;

      if (scrollHeight >= 0) {
        this.$refs.div1Ref.scrollTop = scrollHeight;
      } else {
        this.$refs.div1Ref.scrollTop = 0;
      }
    },
    item2Click(item2, index2) {
      this.curIndex = index2;
      this.lunBoDia = true;
      this.leftScrollHandler();
    },
    lunBoChange(val) {
      this.curIndex = val;
    },
    btnClick(num) {
      let a = this.curIndex + num;
      if (a < 0) {
        a = 0;
      } else if (a == this.arr1.length) {
        a = this.arr1.length - 1;
      }
      this.curIndex = a;
      this.leftScrollHandler();
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.hello {
  width: 600px;
  height: 300px;
  border: 1px solid red;
  overflow: hidden;
  display: flex;
  .div1 {
    height: 100%;
    width: 100px;
    overflow: auto;
  }
  .div2 {
    position: relative;
    flex: 1;
    .youMainDiv {
      overflow: auto;
      height: 300px;
      .rightDiv {
        display: flex;
        flex-wrap: wrap;
      }
    }
    .lunBoDiv {
      position: absolute;
      top: 0;
      left: 0;
      right: 70px;
      height: 250px;
      background: pink;
      scroll-behavior: unset;
    }
  }
}
.active {
  color: red;
}
.active2 {
  border: 1px solid red;
}
.item1Div {
  cursor: pointer;
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值