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

寿司网站CSS问题:主图滚动抖动、导航栏移动端失效及动画异常

寿司网站CSS问题解决方案

问题1:桌面全屏模式下滚动时main-section背景图抖动

  • 给main-section添加硬件加速属性,强制浏览器用GPU渲染,避免抖动:
    .main-section {
      transform: translateZ(0);
      will-change: transform;
    }
    
  • 若使用background-attachment: fixed导致抖动,改用伪元素模拟固定背景:
    .main-section {
      position: relative;
      overflow: hidden;
    }
    .main-section::before {
      content: "";
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-image: url("你的背景图路径");
      background-size: cover;
      z-index: -1;
    }
    

问题2:移动端滚动时nav-bar无法收缩变小

  • 确认移动端媒体查询断点正确,给nav添加过渡样式:
    @media (max-width: 768px) {
      .nav-bar {
        transition: all 0.3s ease;
        height: 80px; /* 默认高度 */
      }
      .nav-bar.shrunk {
        height: 50px; /* 收缩后高度 */
        padding: 0 15px;
      }
    }
    
  • 优化滚动事件监听的移动端兼容性,添加passive选项避免阻塞:
    window.addEventListener('scroll', () => {
      const nav = document.querySelector('.nav-bar');
      nav.classList.toggle('shrunk', window.scrollY > 50);
    }, { passive: true });
    

问题3:网站首次加载时预设动画自动启动

  • 初始状态禁用动画,通过JS控制触发时机:
    .animated-element {
      animation: none;
    }
    .animated-element.active {
      animation: sushi-fade 1.2s ease forwards;
    }
    
  • 示例:用户滚动到目标区域时触发动画:
    const observer = new IntersectionObserver((entries) => {
      entries.forEach(entry => {
        if (entry.isIntersecting) {
          entry.target.classList.add('active');
          observer.unobserve(entry.target);
        }
      });
    });
    observer.observe(document.querySelector('.animated-element'));
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 02:22:09