You need to enable JavaScript to run this app. 如何实现无需hover、每3秒自动循环的shine-box扫光效果
优惠活动
大模型
产品
解决方案
定价
更多

如何实现无需hover、每3秒自动循环的shine-box扫光效果

自动光泽扫过效果实现

代码修改点

  • 修复原有.shine-box样式中尺寸声明遗漏分号的问题,避免CSS解析失效
  • 移除基于hover触发的过渡逻辑,改用CSS关键帧动画实现无交互自动循环
  • 动画总周期设为3秒:前1秒完成从左到右的扫光动作,后2秒光效停在容器外侧不可见,无反向移动效果

完整代码

CSS

body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: darkblue;
}

img {
  border: 0;
}

.shine-box {
  position: absolute;
  width: 200px;
  height: 200px;
  overflow: hidden;
  border-radius: 40%;
}

.shine-box:before {
  position: absolute;
  top: 0;
  left: -500px;
  content: "";
  width: 120px;
  height: 500px;
  background: rgba(255, 255, 255, 0.6);
  transform: skew(-50deg);
  animation: shineMove 3s infinite linear;
}

@keyframes shineMove {
  0% {
    left: -500px;
  }
  33% {
    left: 655px;
  }
  100% {
    left: 655px;
  }
}

HTML

<div class="shine-box">
  <img class="neko" src="neko-fin.png" alt="neko.png">
</div>

效果说明

  • 页面加载后自动启动效果,无需鼠标移入等用户操作
  • 每3秒完成一次完整扫光,循环往复
  • 扫光速度均匀,和原有hover触发的视觉效果完全一致

内容的提问来源于stack exchange,提问作者DoCkane

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.30 06:36:03