vue实现鼠标滑动展示tab栏切换

 更新时间:2022年04月14日 15:59:31   作者:逆风优雅  
这篇文章主要为大家详细介绍了vue实现鼠标滑动展示tab栏切换,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了vue实现鼠标滑动展示tab栏切换的具体代码,供大家参考,具体内容如下

动画效果:

代码如下:

<template>
  <div id="header">
    <div class="conten_width">
      <div class="contnet_width_content">
        <div style="    transform: translateX(-242px);" >
          <img src="./../../assets/img/logo.png" alt="" />
        </div>
        <ul class="header_ul">
          <li
            v-for="(v, i) in liList"
            :key="i"
            :class="{ chosed: active === i }"
            @mouseover="mouserOver(i, v.type)"
           
          >
            {{ v.title }} <a-icon v-if="v.show" :type="v.img" />
          </li>
        </ul>
        <div v-if="dropDownActive==='text1'|| dropDownActive ==='text2'" class="dropDownContent" @mouseleave="contentmouseleave">
          <div v-if="active===0" @mousemove="productContentMouseover('text1')" class="porductContentStyle">产品</div>
          <div v-if="active===1" @mousemove="planContentMouseover('text2')" class="planContentStyle">解决方案</div>
        </div>
        <a-input-search
          placeholder="input search text"
          class="header_input"
          @search="onSearch"
        />
        <span class="header_right1">文档</span>
        <span class="header_right2">控制台</span>
      </div>
    </div>
  </div>
</template>
 
<script>
export default {
  name: "homeLayoutHeader",
  data() {
    return {
      liList: [
        {
          type: "text1",
          title: "产品",
          img: "down",
          show: true,
        },
        {
          type: "text2",
 
          title: "解决方案",
          img: "down",
          show: true,
        },
        {
          type: "text3",
 
          title: "支持与服务",
          show: false,
        },
        {
          type: "text4",
          title: "了解我们",
          show: false,
        },
      ],
      dropDownActive:'',
      active: 0,
    };
  },
  methods: {
    mouserOver(v, tp) {
      //鼠标移动上去的事件
      this.dropDownActive = tp
      this.active
      this.active = v;
      this.liList.map((item, index) => {
        if (v === index) {
          item.img = "up";
        } else {
          item.img = "down";
        }
      });
    },
    contentmouseleave(){
      // 鼠标离开下拉内容区的操作
      this.dropDownActive = ''
      this.liList.map(item=>{
        item.img = 'down'
      })
 
    },
    productContentMouseover(value){
      // 鼠标在产品下面内容区的操作
      this.dropDownActive = value
    },
    planContentMouseover(value){
      // 鼠标在解决方案下面内容区的操作
      this.dropDownActive = value
    },
 
    onSearch() {
      console.log(12);
    },
  },
};
</script>
 
<style scoped>
* {
  margin: 0;
  padding: 0;
}
.conten_width {
  height: 62px;
  width: 1200px;
  margin: 0 auto;
  box-sizing: border-box;
}
.contnet_width_content {
  height: 62px;
  width: 1200px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.header_ul {
  display: flex;
  width: 340px;
  height: 14px;
  justify-content: space-between;
  transform: translateX(-169px);
}
.header_ul li {
  padding-bottom: 36px;
  cursor: pointer;
}
.header_input {
  width: 200px;
  transform: translateX(170px);
}
.header_right1 {
  transform: translateX(210px);
}
.header_right2{
  transform: translateX(240px);
}
.chosed {
  border-bottom: 2px solid red;
}
.dropDownContent {
  /* margin: 0 auto; */
 
  position: absolute;
  z-index: 6;
  top: 63px;
}
.porductContentStyle{
  width: 1000px;
  height: 300px;
  background: red;
 
}
.planContentStyle{
    width: 800px;
  height: 300px;
  background: green;
}
</style>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • 基于vue-draggable 实现三级拖动排序效果

    基于vue-draggable 实现三级拖动排序效果

    这篇文章主要介绍了基于vue-draggable 实现三级拖动排序效果,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-01-01
  • VUE元素的隐藏和显示(v-show指令)

    VUE元素的隐藏和显示(v-show指令)

    本篇文章主要介绍了VUE元素的隐藏和显示(v-show指令),具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-06-06
  • vue项目中onscroll的坑及解决

    vue项目中onscroll的坑及解决

    这篇文章主要介绍了vue项目中onscroll的坑及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-03-03
  • vue.js中ref和$refs的使用及示例讲解

    vue.js中ref和$refs的使用及示例讲解

    这篇文章主要给大家介绍了关于vue.js中ref和$refs使用的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用vue.js具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-08-08
  • vue element实现多个Formt表单同时验证

    vue element实现多个Formt表单同时验证

    这篇文章主要介绍了vue element实现多个Formt表单同时验证方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-06-06
  • vue3中vuex与pinia的踩坑笔记记录

    vue3中vuex与pinia的踩坑笔记记录

    Vuex是一个专为Vue.js应用程序开发的状态管理模式,它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化,这篇文章主要给大家介绍了关于vue3中vuex与pinia踩坑的相关资料,需要的朋友可以参考下
    2021-12-12
  • 15 分钟掌握vue-next响应式原理

    15 分钟掌握vue-next响应式原理

    这篇文章主要介绍了15 分钟掌握vue-next响应式原理,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-10-10
  • vue中如何动态添加样式

    vue中如何动态添加样式

    这篇文章主要介绍了vue中如何动态添加样式问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-06-06
  • vue页面加载时的进度条功能(实例代码)

    vue页面加载时的进度条功能(实例代码)

    这篇文章主要介绍了vue页面加载时的进度条功能,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-01-01
  • vue2.0 如何把子组件的数据传给父组件(推荐)

    vue2.0 如何把子组件的数据传给父组件(推荐)

    这篇文章主要介绍了vue2.0 如何把子组件的数据传给父组件,需要的朋友可以参考下
    2018-01-01

最新评论