欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

vue鼠标移入添加class样式,鼠标移出去除样式(active)实现方法

程序员文章站 2022-07-22 08:57:25
鼠标移入添加class样式 html html绑定事件,加入或者移出class为active

鼠标移入添加class样式

html

html绑定事件,加入或者移出class为active

vue鼠标移入添加class样式,鼠标移出去除样式(active)实现方法

<div class="col-lg-3 col-xs-6 paddingleft com_marginbtm10 chooseplan" v-on:mouseover="changeactive($event)" v-on:mouseout="removeactive($event)">
  流量套餐
</div>

js

这里除了active这个class需要动态添加或者减去,其他的皆是移入移出都需要的class

vue鼠标移入添加class样式,鼠标移出去除样式(active)实现方法

methods:{
   changeactive($event){
       $event.currenttarget.classname="col-lg-3 col-xs-6 paddingleft com_marginbtm10 chooseplan active";
   },
   removeactive($event){
       $event.currenttarget.classname="col-lg-3 col-xs-6 paddingleft com_marginbtm10 chooseplan";
   }
},

拓展知识:vue实现鼠标移入移出事件

如下所示:

    <div class="index_tabletitle clearfix" v-for="(item,index) in table_tit">
     <div class="indexitem">
      <span :title="item.name">{{item.name}}</span>
      <span class="mypor">
       <i class="icon" @mouseenter="enter(index)" @mouseleave="leave()"></i>
       <div v-show="seen&&index==current" class="index-show">
        <div class="tip_wrapinner">{{item.det}}</div>
       </div>
      </span>
     </div>
    </div>
 export default {
  data(){
   return{
    seen:false,
    current:0
   }
  },
  methods:{
   enter(index){
    this.seen = true;
    this.current = index;
   },
   leave(){
    this.seen = false;
    this.current = null;
   }
  }
 }

以上这篇vue鼠标移入添加class样式,鼠标移出去除样式(active)实现方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。