css 希望平稳地从悬停状态转换

5lhxktic  于 2023-10-21  发布在  其他
关注(0)|答案(2)|浏览(123)

我现在有一个过渡,它在悬停时做了一个容易的进出,但是一旦我离开div容器,它就会立即返回到它的原始状态(没有圆锥渐变边界),没有过渡。我该怎么做才能解决这个问题?
我尝试将transition设置为div类本身,然后尝试将transition应用于::before伪。::before转换只在div容器上的悬停时有效,而在我离开div容器时无效。附加链接到代码的屏幕截图图像。
我的网址是matthewcwolfe.com

.wp-block-group.has-base-background-color.has-background.is-layout-flow.wp-container-7.wp-block-group-is-layout-flow::before {

content:"";
position: absolute;
inset: 0;
transition: all .2s ease-in-out;
opacity: 0;

}

.wp-block-group.has-base-background-color.has-background.is-layout-flow.wp-container-7.wp-block-group-is-layout-flow:hover::before {

background: conic-gradient(from 90deg at 40% -25%, #ffd700, #f79d03, #ee6907, #e6390a, #de0d0d, #d61039, #cf1261, #c71585, #cf1261, #d61039, #de0d0d, #ee6907, #f79d03, #ffd700, #ffd700, #ffd700);
transform: translate3d(0,0,-1px);
filter: blur(10px);
clip-path: polygon(-100vmax -100vmax,100vmax -100vmax,100vmax 100vmax,-100vmax 100vmax,-100vmax -100vmax,0 0,0 100%,100% 100%,100% 0,0 0);  
opacity: 1;

}
4ktjp1zp

4ktjp1zp1#

问题是backgroundclip-path最初没有设置为非悬停状态。所以当你悬停时,它会过渡到渐变背景和剪切形状,但是当你移除悬停时,它没有任何东西可以过渡(因此会立即消失)。
您可以通过将相同的backgroundclip-path复制到非悬停状态来修复此问题。这应该是好的,因为你是从0不透明度过渡到1不透明度反正。我在你的网站上测试了它在devtools,它似乎工作。

.wp-block-group.has-base-background-color.has-background.is-layout-flow.wp-container-7.wp-block-group-is-layout-flow::before {

content:"";
position: absolute;
inset: 0;
transition: all .2s ease-in-out;
opacity: 0;
/* SAME BACKGROUND ON NON-HOVER */
background: conic-gradient(from 90deg at 40% -25%, #ffd700, #f79d03, #ee6907, #e6390a, #de0d0d, #d61039, #cf1261, #c71585, #cf1261, #d61039, #de0d0d, #ee6907, #f79d03, #ffd700, #ffd700, #ffd700);
/* SAME CLIP-PATH ON NON-HOVER */
clip-path: polygon(-100vmax -100vmax,100vmax -100vmax,100vmax 100vmax,-100vmax 100vmax,-100vmax -100vmax,0 0,0 100%,100% 100%,100% 0,0 0); 

}

.wp-block-group.has-base-background-color.has-background.is-layout-flow.wp-container-7.wp-block-group-is-layout-flow:hover::before {

background: conic-gradient(from 90deg at 40% -25%, #ffd700, #f79d03, #ee6907, #e6390a, #de0d0d, #d61039, #cf1261, #c71585, #cf1261, #d61039, #de0d0d, #ee6907, #f79d03, #ffd700, #ffd700, #ffd700);
transform: translate3d(0,0,-1px);
filter: blur(10px);
clip-path: polygon(-100vmax -100vmax,100vmax -100vmax,100vmax 100vmax,-100vmax 100vmax,-100vmax -100vmax,0 0,0 100%,100% 100%,100% 0,0 0);  
opacity: 1;
}

编辑:实际上,你也可以将backgroundclip-path从悬停状态中删除,并将它们保持在非悬停状态,因为它们根本不会改变。重要的是filteropacity正确转换。

nfzehxib

nfzehxib2#

如果你想寻找平滑过渡的颜色,而不是圆锥渐变的边界颜色,那么试试这个
完全删除下面的代码

.wp-block-group.has-base-background-color.has-background.is-layout-flow.wp-container-7.wp-block-group-is-layout-flow::before {
  content: "";
  position: absolute;
  inset: 0;
  transition: all .2s ease-in-out;
  opacity: 0;
}

并添加此

.wp-block-group.has-base-background-color.has-background.is-layout-flow.wp-container-7.wp-block-group-is-layout-flow:hover {
    box-shadow: 0px 0px 20px 0px #f5a00e;
}

相关问题