页面中鼠标触碰字体后切换颜色且随鼠标移走后改变

such as:
在这里插入图片描述
鼠标移上去:
在这里插入图片描述
颜色会随着鼠标移动变回原来的颜色
实现这个效果其实很简单:
less代码:

      li {
        display: inline-block;
        width: 50/100rem;
        height: 100%;
        line-height: 50/100rem;
        text-align: center;
      }
      	// 上面的不重要
      li:hover {
        //animation: 动画名称 动画时长 动画运动速度 动画延迟时间 执行次数 是否要往返动画 ;
        animation: color_change 0.3s linear 0ms 1;
        animation-fill-mode: forwards;
        // 这两行是实现代码
        //animation-fill-mode 属性规定动画在播放之前或之后,其动画效果是否可见。
        // animation-fill-mode : none | forwards | backwards | both;
        // 
      }
      
@keyframes color_change {
  from {
    color: #ffffff;
  }
  to {
    color: #fa0000;
  }
}

animation-fill-mode 的值与描述:

描述
none不改变默认行为
forwards当动画完成后,保持最后一个属性值(在最后一个关键帧中定义)
backwards在 animation-delay 所指定的一段时间内,在动画显示之前,应用开始属性值(在第一个关键帧中定义)。
both向前和向后填充模式都被应用。
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
如果你想要实现的是鼠标离开文字的特效,可以使用CSS的伪类选择器:hover和transition属性。 首先,在CSS定义文字的样式,例如: ``` .text { font-size: 24px; color: #333; text-shadow: 1px 1px 1px #ddd; transition: all 0.3s ease-in-out; } ``` 这里也添加了一个过渡效果。 然后,使用:hover伪类选择器来为鼠标悬停的文字添加特效,例如: ``` .text:hover { text-decoration: underline; color: #ff6600; text-shadow: 1px 1px 1px #ff6600; } ``` 这里的text-decoration属性用来添加下划线特效,color属性用来改变文字颜色,text-shadow属性用来改变文字阴影颜色。 最后,使用.text:hover之外的选择器来定义鼠标离开文字的特效,例如: ``` .text { font-size: 24px; color: #333; text-shadow: 1px 1px 1px #ddd; transition: all 0.3s ease-in-out; text-decoration: none; } .text:hover { text-decoration: underline; color: #ff6600; text-shadow: 1px 1px 1px #ff6600; } .text:after { content: ""; display: block; height: 2px; width: 0; background-color: #ff6600; transition: all 0.3s ease-in-out; } .text:hover:after { width: 100%; } ``` 这里使用了伪元素::after来为文字添加一个下划线,当鼠标离开文字,下划线会逐渐消失。 完整的CSS代码如下: ``` .text { font-size: 24px; color: #333; text-shadow: 1px 1px 1px #ddd; transition: all 0.3s ease-in-out; text-decoration: none; } .text:hover { text-decoration: underline; color: #ff6600; text-shadow: 1px 1px 1px #ff6600; } .text:after { content: ""; display: block; height: 2px; width: 0; background-color: #ff6600; transition: all 0.3s ease-in-out; } .text:hover:after { width: 100%; } ``` 这样,当鼠标离开文字,下划线会逐渐消失,从而实现了文字特效。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

无名之辈无名之辈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值