CSS Vue ul鼠标移动到多个li标签上字体高亮

1.字体高亮
      <ul v-for="(item,index) in tableData" :key="index" class="smart_nav_con">
        <li :class="colorHover===index?'smart_index':'a_white'" style="display:inline-block; width: 100%" @mouseenter="spanHover(index)">
          <a class="white a_color bnContentCss" @click.prevent="xiangxi(item)">{{ item.bnContent }}</a>
          <a class="white a_color bnDateCss" @click.prevent="xiangxi(item)">{{ item.bnDate }}</a>
          <a class="white a_color bnPublishNameCss" @click.prevent="xiangxi(item)">{{ item.bnPublishName }}</a>
        </li>
      </ul>
data(){
	return{
	      colorHover: 0
	}
}
methods:{
    spanHover: function(index) {
      this.colorHover = index
    }
}
`
```css
  .smart_nav_con{
    color:black;
    position: relative;
    padding-left: 10px;
    padding-top: 12px;
  }
  .smart_nav_con .smart_index .a_white{
    color:black;
  }
  .smart_nav_con .smart_index .a_color{
    color:#00a0e9;
  }
  .smart_nav_con li a{
    color:black;
  }
  .smart_nav_con .smart_index a{
    color:#00a0e9;
  }
  .bnContentCss{
    font-size: 14px;
    color: #666666;
    width: 60%;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
    display: inline-block
  }
  .bnDateCss{
    font-size: 14px;
    color: #9b9b9b;
    display: inline-block;
    float: right;
    margin-right: 13px;
  }
  .bnPublishNameCss{
    font-size: 14px;
    color: #82796f;
    display:inline-block;
    float: right;
    position: relative;
    right: 15px;
  }
  .ulCss{
    list-style: none;
    padding-left: 10px;
    padding-top: 8px;
    color:#fff;
  }
效果

在这里插入图片描述

2.移动到元素上对应改变背景色
    <ul v-for="(item,index) in tableData" :key="index" style="list-style: none;padding-left: 10px;">
      <li :class="active === index?'smart_index':'a_white'" style="display:inline-block; width: 98%" @mouseover="mouseOver(index)" @mouseleave="mouseLeave(index)">
        <a class="circle">
          <div class="circletext" @click.prevent="xiangxi(item)" v-html="formatDate(item.bnDate)" />
        </a>
        <div style="display:inline-block;position: relative;top: 3px;width: 80%;margin-left: 12px">
          <a style="width: 80%" @click.prevent="xiangxi(item)">
            <span class="NoticeTitle">{{ item.bnTitle }}</span>
          </a>
          <a style="width: 80%" @click.prevent="xiangxi(item)">
            <span class="NoticeContent">{{ item.bnContent }}</span>
          </a>
        </div>
      </li>
    </ul>
data(){
	return{
	     active: 0,
	}
}
methods:{
     mouseOver: function(index) {
      this.active = index
    },
    mouseLeave: function(index) {
      this.active = index
    }
}
  .smart_index{
  background-color: #F5F5F5;
}
  .a_white{
    background-color: #ffffff;
  }
效果

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要实现移动高亮显示,可以利用 Vue 自带的过渡动画和数据绑定。 1. 在组件的 `data` 中声明一个 `activeIndex` 变量,用来记录当前高亮的索引值。 ```vue <template> <div> <ul> <li v-for="(item, index) in list" :key="index" @click="activeIndex = index"> {{ item }} </li> </ul> <div class="highlight" :style="{ top: activeIndex * itemHeight + 'px' }" v-show="activeIndex >= 0"></div> </div> </template> <script> export default { data() { return { list: ['item1', 'item2', 'item3', 'item4', 'item5'], activeIndex: -1, itemHeight: 40 // 列表项高度 } } } </script> ``` 2. 在 `<div>` 标签中添加一个名为 `highlight` 的 CSS 类,用来设置高亮效果的样式。 ```vue <template> <div> <ul> <li v-for="(item, index) in list" :key="index" @click="activeIndex = index"> {{ item }} </li> </ul> <div class="highlight" :style="{ top: activeIndex * itemHeight + 'px' }" v-show="activeIndex >= 0"></div> </div> </template> <script> export default { data() { return { list: ['item1', 'item2', 'item3', 'item4', 'item5'], activeIndex: -1, itemHeight: 40 // 列表项高度 } } } </script> <style> .highlight { position: absolute; left: 0; width: 100%; height: 40px; // 列表项高度 background-color: #f0f0f0; transition: top 0.3s ease-in-out; } </style> ``` 3. 绑定 `highlight` 样式中的 `top` 属性到 `activeIndex` 变量,并且使用 `v-show` 指令控制高亮效果的显示。 ```vue <template> <div> <ul> <li v-for="(item, index) in list" :key="index" @click="activeIndex = index"> {{ item }} </li> </ul> <div class="highlight" :style="{ top: activeIndex * itemHeight + 'px' }" v-show="activeIndex >= 0"></div> </div> </template> <script> export default { data() { return { list: ['item1', 'item2', 'item3', 'item4', 'item5'], activeIndex: -1, itemHeight: 40 // 列表项高度 } } } </script> <style> .highlight { position: absolute; left: 0; width: 100%; height: 40px; // 列表项高度 background-color: #f0f0f0; transition: top 0.3s ease-in-out; } </style> ``` 这样,当点击列表项时,会触发 `activeIndex` 的变化,从而控制高亮效果的显示和隐藏,并且通过过渡动画实现了移动高亮效果。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值