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

网站.am-secta元素悬停渐变(Hover gradient)与背景图平滑进出过渡(smooth in and out transition)效果优化求助

Fixing Smooth Hover Transition for .am-secta Element

Let's resolve that flickering transition issue you're facing. The root causes here are:

  • The background image is only loaded when the hover triggers, leading to a delay/flicker as the browser fetches it.
  • Your current transition property doesn't target the background attributes that change on hover, so there's no smooth animation between states.

Here's the revised CSS that maintains your element's position/size while adding a seamless hover transition:

body{ background-color: #212121; }
.iframe-container { padding-top: 29.25%; position: relative; }
.iframe-container iframe { border: 0; height: 360px; left: 15%; position: absolute; top: 0px; width: 70%; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); transition: box-shadow 0.3s ease-in-out; }
.iframe-container iframe:hover { box-shadow: 0 5px 20px rgb(0 0 0 / 160%); }
.m-containera { width: 100%; max-width: 1517px; margin: 0 auto; align-content: center; text-align: center; }

/* Modified .am-secta base styles */
.am-secta {
  padding-top: 40px;
  padding-bottom: 40px;
  background-color: #212121;
  /* Preload the background image and set initial transparent gradient */
  background-image: linear-gradient(180deg, rgba(33,33,33,1) 0%, rgba(29,185,84,0) 100%), url("http://www.piyushcares.com/wp-content/uploads/2018/11/homepagevid.png");
  background-repeat: no-repeat;
  background-position: center center top;
  background-size: cover;
  z-index: 1;
  /* Transition all relevant background properties + color */
  transition: background-image 0.3s ease-in-out, color 0.3s ease-in-out;
}

/* Modified hover state - only adjust the gradient opacity */
.am-secta:hover{
  background-image: linear-gradient(180deg, rgba(33,33,33,1) 0%, rgba(29,185,84,0.5) 100%), url("http://www.piyushcares.com/wp-content/uploads/2018/11/homepagevid.png");
}

.contenta { padding: 0 10px; }
.titls { font-size: 34px; font-weight: 700; text-align: center; color: white; font-family: 'Raleway'; }
.par { color: white; text-align: center; font-weight: normal; font-size: 20px; line-height: 1.5; padding-top: 10px; padding-bottom: 45px; font-family: 'Raleway'; }
.inlin { display: none; }
.bold { font-weight: 700; }

Key Changes Explained:

  • Preload the Background: We added the full background image + gradient to the base .am-secta style, but set the green gradient's opacity to 0. This ensures the image loads immediately with the page, not on hover, eliminating flicker.
  • Targeted Transition: Updated the transition property to include background-image (since that's what changes when we adjust the gradient opacity), along with your existing color transition.
  • Simplified Hover State: The hover state only modifies the gradient's opacity from 0 to 0.5—all other background properties stay identical, so the browser can animate the change smoothly without layout shifts.

This approach keeps your element's position and dimensions intact while delivering a seamless hover transition with no flickering.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 18:28:13