You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现垂直导航栏悬停效果并获取相关学习参考资料

垂直导航栏悬停效果实现方案

实现思路:给每个图标套一层外层容器,通过容器的伪元素实现左侧悬停高亮指示条,同时给图标加hover状态的高亮效果强化交互。

调整后代码

结构部分

<LogosContainer>
  <LogoWrapper>
    <Logo src={iconHome} alt="home" />
  </LogoWrapper>
  <LogoWrapper>
    <Logo src={iconGlobe} alt="globe" />
  </LogoWrapper>
  <LogoWrapper>
    <Logo src={iconArchive} alt="archive" />
  </LogoWrapper>
  <LogoWrapper>
    <Logo src={iconPieChart} alt="pie-chart" />
  </LogoWrapper>
  <LogoWrapper>
    <Logo src={iconDollarSign} alt="dollar" />
  </LogoWrapper>
  <LogoWrapper>
    <Logo src={iconDatabase} alt="database" />
  </LogoWrapper>
  <LogoWrapper>
    <Logo src={iconNavigation} alt="navigation" />
  </LogoWrapper>
</LogosContainer>

样式部分(styled-components)

const LogosContainer = styled.div`
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  /* 可按需调整侧边栏的宽度、背景色、高度 */
  width: 64px;
  min-height: 100vh;
  background-color: #1e293b;
`;

// 新增图标外层容器,用来实现左侧指示条
const LogoWrapper = styled.div`
  position: relative;
  margin-bottom: 43px;
  cursor: pointer;
  padding-left: 8px;
  transition: all 0.2s ease;

  &:last-child {
    margin-bottom: 0;
  }

  /* 左侧悬停高亮条 */
  &::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 70%;
    /* 替换为你设计稿对应的高亮颜色 */
    background-color: #6366f1;
    border-radius: 0 3px 3px 0;
    opacity: 0;
    transition: opacity 0.2s ease;
  }

  &:hover::before {
    opacity: 1;
  }

  /* 图标hover高亮效果 */
  &:hover img {
    /* 如果是单色SVG图标可直接改fill属性,此处为img图标的通用高亮效果,可按需调整参数 */
    filter: brightness(1.4) saturate(1.2) drop-shadow(0 0 2px rgba(99, 102, 241, 0.3));
  }
`;

const Logo = styled.img`
  display: block;
`;

可自定义调整项

  • 可以修改伪元素的宽高、颜色、圆角参数,匹配你的设计稿
  • 如果使用SVG组件作为图标,可直接在hover状态下修改fill属性切换颜色,效果更精细
  • 可调整transition的时长和动画曲线,修改交互的流畅度

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 12:54:04