实现基于两点:
- 图形是在被设置了
filter: contrast()
的画布背景上进行动画的 - 进行动画的图形被设置了
filter: blur()
( 进行动画的图形的父元素需要是被设置了filter: contrast()
的画布)
意思是,上面两圆运动的背后,其实是叠加了一张设置了 filter: contrast()
的白色背景,而两个圆形则被设置了 filter: blur()
,两个条件缺一不可。
- <div class=“container”>
- <div class=“filter-mix”></div>
- </div>
- .filter-mix {
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- width: 400px;
- height: 200px;
- filter: contrast(20);
- background: #fff;
- }
- .filter-mix::before {
- content: “”;
- position: absolute;
- width: 100px;
- height: 100px;
- border-radius: 50%;
- background: #333;
- top: 50px;
- left: 40px;
- z-index: 2;
- filter: blur(10px);
- box-sizing: border-box;
- animation: filterBallMove 6s ease-out infinite;
- }
- .filter-mix::after {
- content: “”;
- position: absolute;
- width: 80px;
- height: 80px;
- border-radius: 50%;
- background: red;
- top: 60px;
- rightright: 40px;
- z-index: 2;
- filter: blur(10px);
- animation: filterBallMove2 6s ease-out infinite;
- }
- @keyframes filterBallMove {
- 50% {
- left: 200px;
- }
- }
- @keyframes filterBallMove2 {
- 50% {
- rightright: 200px;
- }
- }
本文链接地址: css 融合效果