我通过在背景中使用 3 个波浪图像制作了这个水波文本动画和图像动画,但我想只用 css 动画和 clip-path css 替换这 3 个背景图像。
我使用了关键帧动画来连续移动背景图像,并在文本中使用剪辑路径来实现像水一样的动画效果。我只是想替换图片而不是文字。
可能吗?如果是,请帮助我...
<section>
<div class="container">
<div class="text-animation">
<div class="text-wrapper">
<h2>ALAP</h2>
<h2>ALAP</h2>
</div>
</div>
<div class="waveDiv animation-wave">
<div class="wave-content-wrapper first-wave">
<div class="wave-image first-image" style="background-image: url('http://front-end-noobs.com/jecko/img/wave-top.png')"></div>
</div>
<div class="wave-content-wrapper second-wave">
<div class="wave-image second-image" style="background-image: url('http://front-end-noobs.com/jecko/img/wave-mid.png')"></div>
</div>
<div class="wave-content-wrapper third-wave">
<div class="wave-image third-image" style="background-image: url('http://front-end-noobs.com/jecko/img/wave-bot.png')"></div>
</div>
</div>
</div>
</section>
@import url("https://fonts.googleapis.com/css2?family=Nunito:wght@600&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Nunito", sans-serif;
}
body {
height: 100%;
}
.text-animation {
background: #0f0f0f;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.text-wrapper {
position: relative;
}
.text-wrapper h2 {
z-index: 4;
color: #f0f0f0;
font-size: 15vw;
white-space: nowrap;
position: absolute;
transform: translate(-50%, -62%);
}
.text-wrapper h2:nth-child(1) {
color: transparent;
-webkit-text-stroke: 2px #f0f0f0;
}
.text-wrapper h2:nth-child(2) {
color: #fff;
animation: wave 4s ease-in-out infinite;
}
@keyframes wave {
/* start point */
0%,
100% {
clip-path: polygon(
0% 46%,
17% 45%,
34% 50%,
56% 61%,
69% 62%,
86% 60%,
100% 51%,
100% 100%,
0% 100%
);
}
/* Mid point */
50% {
clip-path: polygon(
0% 59%,
16% 64%,
33% 65%,
52% 61%,
70% 52%,
85% 47%,
100% 48%,
100% 100%,
0% 100%
);
}
}
/* ********************* Image Waves ************************ */
.waveDiv {
position: absolute;
overflow: hidden;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.wave-content-wrapper {
height: 100%;
width: 100%;
position: absolute;
overflow: hidden;
bottom: -1px;
background-image: linear-gradient(to top, #000000 30%, #002029 90%);
}
.first-wave {
z-index: 3;
opacity: 0.5;
}
.second-wave {
z-index: 2;
opacity: 0.75;
}
.third-wave {
z-index: 1;
}
.wave-image {
width: 200%;
height: 100%;
position: absolute;
left: 0;
background-repeat: repeat no-repeat;
background-position: 0 bottom;
transform-origin: center bottom;
}
.first-image {
background-size: 50% 100px;
}
.animation-wave .first-image {
animation: move-wave 3s;
-webkit-animation: move-wave 3s;
-webkit-animation-delay: 2s;
animation-delay: 2s;
}
.second-image {
background-size: 50% 120px;
}
.animation-wave .second-image {
animation: waves 10s linear infinite;
}
.third-image {
background-size: 50% 140px;
}
.animation-wave .third-image {
animation: waves 15s linear infinite;
}
@keyframes waves {
0% {
transform: translateX(0) scaleY(1);
}
50% {
transform: translateX(-25%) scaleY(0.55);
}
100% {
transform: translateX(-50%) scaleY(1);
}
}
@import url("https://fonts.googleapis.com/css2?family=Nunito:wght@600&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Nunito", sans-serif;
}
body {
height: 100%;
}
.text-animation {
background: #0f0f0f;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.text-wrapper {
position: relative;
}
.text-wrapper h2 {
z-index: 4;
color: #f0f0f0;
font-size: 15vw;
white-space: nowrap;
position: absolute;
transform: translate(-50%, -62%);
}
.text-wrapper h2:nth-child(1) {
color: transparent;
-webkit-text-stroke: 2px #f0f0f0;
}
.text-wrapper h2:nth-child(2) {
color: #fff;
animation: wave 4s ease-in-out infinite;
}
@keyframes wave {
/* start point */
0%,
100% {
clip-path: polygon(
0% 46%,
17% 45%,
34% 50%,
56% 61%,
69% 62%,
86% 60%,
100% 51%,
100% 100%,
0% 100%
);
}
/* Mid point */
50% {
clip-path: polygon(
0% 59%,
16% 64%,
33% 65%,
52% 61%,
70% 52%,
85% 47%,
100% 48%,
100% 100%,
0% 100%
);
}
}
/* ********************* Image Waves ************************ */
.waveDiv {
position: absolute;
overflow: hidden;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.wave-content-wrapper {
height: 100%;
width: 100%;
position: absolute;
overflow: hidden;
bottom: -1px;
background-image: linear-gradient(to top, #000000 30%, #002029 90%);
}
.first-wave {
z-index: 3;
opacity: 0.5;
}
.second-wave {
z-index: 2;
opacity: 0.75;
}
.third-wave {
z-index: 1;
}
.wave-image {
width: 200%;
height: 100%;
position: absolute;
left: 0;
background-repeat: repeat no-repeat;
background-position: 0 bottom;
transform-origin: center bottom;
}
.first-image {
background-size: 50% 100px;
}
.animation-wave .first-image {
animation: move-wave 3s;
-webkit-animation: move-wave 3s;
-webkit-animation-delay: 2s;
animation-delay: 2s;
}
.second-image {
background-size: 50% 120px;
}
.animation-wave .second-image {
animation: waves 10s linear infinite;
}
.third-image {
background-size: 50% 140px;
}
.animation-wave .third-image {
animation: waves 15s linear infinite;
}
@keyframes waves {
0% {
transform: translateX(0) scaleY(1);
}
50% {
transform: translateX(-25%) scaleY(0.55);
}
100% {
transform: translateX(-50%) scaleY(1);
}
}
<section>
<div class="container">
<div class="text-animation">
<div class="text-wrapper">
<h2>ALAP</h2>
<h2>ALAP</h2>
</div>
</div>
<div class="waveDiv animation-wave">
<div class="wave-content-wrapper first-wave">
<div class="wave-image first-image" style="background-image: url('http://front-end-noobs.com/jecko/img/wave-top.png')"></div>
</div>
<div class="wave-content-wrapper second-wave">
<div class="wave-image second-image" style="background-image: url('http://front-end-noobs.com/jecko/img/wave-mid.png')"></div>
</div>
<div class="wave-content-wrapper third-wave">
<div class="wave-image third-image" style="background-image: url('http://front-end-noobs.com/jecko/img/wave-bot.png')"></div>
</div>
</div>
</div>
</section>