使用背景过滤器影响孩子的不透明度过渡

IT技术 javascript css reactjs framer-motion
2021-04-28 03:32:29

我试图在进入视口时运行过渡。我希望卡片简单地不透明......我的 div 中有一个代理元素,背景过滤器应用于应用“磨砂玻璃”外观。当父级有任何类型的不透明度变化时,过滤器根本不适用并导致笨拙的动画。这是上下文的 CSS:

.card {
  width: 100%;
  position: relative;
  min-height: 320px;
  border-radius: 12px;
  overflow: hidden;
  padding: 32px 24px;
  box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.16);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 45rem;
  margin: 8px 0;
  transition: all 0.4s ease;

.backdrop {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    border-radius: 12px;
    backdrop-filter: blur(32px) brightness(115%);
    background-color: rgba(255, 255, 255, 0.16);
  }
}

我也尝试对孩子应用过渡,还尝试将以下内容应用于父母和背景:

  -webkit-backface-visibility: hidden;
  -webkit-transform: translate3d(0, 0, 0);
  -webkit-perspective: 1000;
1个回答

你可以@keyframes用来制作这样的动画:

.card {
  width: 100%;
  position: relative;
  min-height: 320px;
  border-radius: 12px;
  overflow: hidden;
  padding: 32px 24px;
  box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.16);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 45rem;
  margin: 8px 0;
  animation: fadein 3s;

.backdrop {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    border-radius: 12px;
    backdrop-filter: blur(32px) brightness(115%);
    background-color: rgba(255, 255, 255, 0.16);
  }
}

@keyframes fadein {
  from{opacity: 0;}
  50%{opacity: 0.5} /* Ignored */ 
  to{opacity: 1;}

您可以将其更改为也许在悬停时进行更改。