电梯导航----基础版本

<template>
  <a-modal
   :maskClosable="false"
   title='导航对应模块内容滚动变化'
   v-model="visible"
   :width="950"
   :footer="null">
 
    <div class="wrapper">
      <div class="left_content">
        <p  v-for="(item,index) in list" :key='index' :class="{'active':isActive==index}"  @click="scrollIndex(index,item.id)">{{item.title}}</p>   
     
      </div>
      <div class="right_content" id="right_content">
        <div id="block1">1</div>
        <div id="block2">2</div>
        <div id="block3">3</div>
      </div>
    
	  </div>


   
  </a-modal>
</template>
 

<script>

export default {
 

 data() {
   return {
     visible: false,
     list: [{
            id: 'block1',
            title: '模块1'
          },
          {
            id: 'block2',
            title: '模块2'
          },
          {
            id: 'block3',
            title: '模块3'
          },
        ],
        isActive: null,
        block_one: '',
        block_two: '',
        block_three: '',
        bodyHeight: 0,
        tar: null,

  };
  },
  watch: {
      bodyHeight: {
        handler(newVal) {
          if (newVal >= this.block_one) {
            this.isActive = 0
          }
          if (newVal >= this.block_two) {
            this.isActive = 1
          }
          if (newVal >= this.block_three) {
            this.isActive = 2
          }
          if (newVal >= this.block_four) {
            this.isActive = 3
          }
          if (newVal == 0) {
            this.isActive = 0
          }
        },
        immediate: true,
        deep: true
      }
    },

 

methods: {
  // ---打开弹框
  showModal () {
    this.visible = true
  this.$nextTick(()=>{
    this.open()
  })
  
  },
  // ---关闭弹框
  handleOk () {
    this.visible = false
  },

  scrollIndex(val, id) {
	        this.isActive = val
	        this.$nextTick(() => {
	          let targetbox = document.getElementById(id)
	          let height = targetbox.offsetTop
	          this.tar.scrollTop = height
	        })
	    },
      ccroll() {
        console.log('滚动中',this.tar.scrollTop);
        	this.bodyHeight =  this.tar.scrollTop 
          this.open()
       
      	},
    open(){
    this.tar = document.getElementById('right_content')
    this.tar.addEventListener("scroll", this.ccroll);
   		//先获取右侧内容区域每个模块的高度
		this.block_one = document.getElementById('block1').offsetTop
 		this.block_two = document.getElementById('block2').offsetTop
 		this.block_three = document.getElementById('block3').offsetTop
  
 		
   },


},
};
</script>
<style scoped lang="less">
.right_content{
  position:relative;
  height:200px;
  overflow:auto;
}
.wrapper{

  display:flex;
  .left_content{
    width:90px;
  }
  .right_content{
    width: calc(100% - 100px);
  }
}

.active {
	    color: orange;
	  }
    .right_content{
      div{
        height:300px;
        border:1px solid red;
        margin-top:20px;
        width:100%;
      }
    }
</style>

在父组件引用一下  ==列如

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值