У меня есть раздел героя на моей веб-странице, и я хотел бы создать анимированную волновую анимацию внизу. Раздел героя отображает фоновое видео.
У меня работает видеофон и анимированные волны, однако я застрял с прямой синей границей между ними, как показано на рисунке.
Я могу использовать отрицательное поле, чтобы поднять волны поверх фона видео, но в итоге вы все равно получите жесткую границу.
Возможно, именно так я реализовал SVG, но сейчас я немного запутался.
Для краткости я удалил некоторые элементы (кнопки, так как это не имеет значения). Это HTML.
<div class = "newHero">
<h2>Using Sail Training to Inspire & Change Lives</h2>
<p>Morvargh Sailing Project is a youth development organisation that helps young people become more confident, more resilient, more motivated and better able to communicate though volunteer led, life-changing sail training voyages.</p>
<a href = "tel:xxxx" class = "d-flex align-items-center"><i class = "fa-solid fa-phone-volume"></i>Contact Us</a>
<video class = "video-bg" autoplay muted loop>
<source src = "frontend/vid/MSP.mp4" type = "video/mp4" >
</video>
</div>
<div class = "waves">
<svg class = "waves" xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 24 150 28 " preserveAspectRatio = "none">
<defs>
<path id = "wave-path" d = "M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z">
</defs>
<g class = "wave1">
<use xlink:href = "#wave-path" x = "50" y = "3" fill = "rgba(255,255,255, .1)">
</g>
<g class = "wave2">
<use xlink:href = "#wave-path" x = "50" y = "0" fill = "rgba(255,255,255, .2)">
</g>
<g class = "wave3">
<use xlink:href = "#wave-path" x = "50" y = "9" fill = "#fff">
</g>
</svg>
</div>
Это CSS
<style>
.newHero {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
background-image: linear-gradient(160deg, rgba(46, 59, 78,1), rgba(255, 64, 64,0.3));
/*background: rgba(46, 59, 78, 0.85);*/
color: white;
position: relative;
overflow: hidden;
min-height: 70vh;
}
.newHero h2 {
font-size: 48px;
font-weight: 700;
margin-bottom: 10px;
color: #fff;
max-width: 550px;
}
.newHero p {
max-width: 550px;
color: rgba(255, 255, 255, 0.6);
font-weight: 600;
font-size: 1.2em;
margin-bottom: 30px;
}
.newHero a {
font-size: 20px;
transition: 0.5s;
margin-left: 25px;
color: rgba(255, 255, 255, 1);
font-weight: 600;
}
.newHero a:hover i {
color: #fff;
}
.newHero i {
color: rgba(255, 255, 255, 0.5);
font-size: 32px;
transition: 0.3s;
line-height: 0;
margin-right: 12px;
}
.video-bg {
position: absolute;
z-index: -1;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
min-width: 100%;
min-height: 100%;
}
.waves {
background: rgba(46, 59, 78, 0.75);
height: 60px;
width: 100%;
z-index: 10;
}
.wave1 use {
-webkit-animation: move-forever1 10s linear infinite;
animation: move-forever1 10s linear infinite;
-webkit-animation-delay: -2s;
animation-delay: -2s;
}
.wave2 use {
-webkit-animation: move-forever2 8s linear infinite;
animation: move-forever2 8s linear infinite;
-webkit-animation-delay: -2s;
animation-delay: -2s;
}
.wave3 use {
-webkit-animation: move-forever3 6s linear infinite;
animation: move-forever3 6s linear infinite;
-webkit-animation-delay: -2s;
animation-delay: -2s;
}
@-webkit-keyframes move-forever1 {
0% {
transform: translate(85px, 0%);
}
100% {
transform: translate(-90px, 0%);
}
}
@keyframes move-forever1 {
0% {
transform: translate(85px, 0%);
}
100% {
transform: translate(-90px, 0%);
}
}
@-webkit-keyframes move-forever2 {
0% {
transform: translate(-90px, 0%);
}
100% {
transform: translate(85px, 0%);
}
}
@keyframes move-forever2 {
0% {
transform: translate(-90px, 0%);
}
100% {
transform: translate(85px, 0%);
}
}
@-webkit-keyframes move-forever3 {
0% {
transform: translate(-90px, 0%);
}
100% {
transform: translate(85px, 0%);
}
}
@keyframes move-forever3 {
0% {
transform: translate(-90px, 0%);
}
100% {
transform: translate(85px, 0%);
}
}
</style>
Может ли кто-нибудь дать мне несколько советов о том, как сделать анимацию волны без жесткой границы?
У класса .waves есть фоновый цвет, который нужно удалить. Затем вы можете использовать отрицательную маржу, чтобы тянуть волны вверх. Я также добавил position:relative к .waves, чтобы применить z-index.
.newHero {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
background-image: linear-gradient(160deg, rgba(46, 59, 78,1), rgba(255, 64, 64,0.3));
/*background: rgba(46, 59, 78, 0.85);*/
color: white;
position: relative;
overflow: hidden;
min-height: 70vh;
}
.newHero h2 {
font-size: 48px;
font-weight: 700;
margin-bottom: 10px;
color: #fff;
max-width: 550px;
}
.newHero p {
max-width: 550px;
color: rgba(255, 255, 255, 0.6);
font-weight: 600;
font-size: 1.2em;
margin-bottom: 30px;
}
.newHero a {
font-size: 20px;
transition: 0.5s;
margin-left: 25px;
color: rgba(255, 255, 255, 1);
font-weight: 600;
}
.newHero a:hover i {
color: #fff;
}
.newHero i {
color: rgba(255, 255, 255, 0.5);
font-size: 32px;
transition: 0.3s;
line-height: 0;
margin-right: 12px;
}
.video-bg {
position: absolute;
z-index: -1;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
min-width: 100%;
min-height: 100%;
}
.waves {
height: 60px;
width: 100%;
margin-top: -30px;
z-index: 10;
position: relative;
}
.wave1 use {
-webkit-animation: move-forever1 10s linear infinite;
animation: move-forever1 10s linear infinite;
-webkit-animation-delay: -2s;
animation-delay: -2s;
}
.wave2 use {
-webkit-animation: move-forever2 8s linear infinite;
animation: move-forever2 8s linear infinite;
-webkit-animation-delay: -2s;
animation-delay: -2s;
}
.wave3 use {
-webkit-animation: move-forever3 6s linear infinite;
animation: move-forever3 6s linear infinite;
-webkit-animation-delay: -2s;
animation-delay: -2s;
}
@-webkit-keyframes move-forever1 {
0% {
transform: translate(85px, 0%);
}
100% {
transform: translate(-90px, 0%);
}
}
@keyframes move-forever1 {
0% {
transform: translate(85px, 0%);
}
100% {
transform: translate(-90px, 0%);
}
}
@-webkit-keyframes move-forever2 {
0% {
transform: translate(-90px, 0%);
}
100% {
transform: translate(85px, 0%);
}
}
@keyframes move-forever2 {
0% {
transform: translate(-90px, 0%);
}
100% {
transform: translate(85px, 0%);
}
}
@-webkit-keyframes move-forever3 {
0% {
transform: translate(-90px, 0%);
}
100% {
transform: translate(85px, 0%);
}
}
@keyframes move-forever3 {
0% {
transform: translate(-90px, 0%);
}
100% {
transform: translate(85px, 0%);
}
}
<div class = "newHero">
<h2>Using Sail Training to Inspire & Change Lives</h2>
<p>Morvargh Sailing Project is a youth development organisation that helps young people become more confident, more resilient, more motivated and better able to communicate though volunteer led, life-changing sail training voyages.</p>
<a href = "tel:xxxx" class = "d-flex align-items-center"><i class = "fa-solid fa-phone-volume"></i>Contact Us</a>
<video class = "video-bg" autoplay muted loop>
<source src = "frontend/vid/MSP.mp4" type = "video/mp4" >
</video>
</div>
<div class = "waves">
<svg class = "waves" xmlns = "http://www.w3.org/2000/svg" xmlns:xlink = "http://www.w3.org/1999/xlink" viewBox = "0 24 150 28 " preserveAspectRatio = "none">
<defs>
<path id = "wave-path" d = "M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z">
</defs>
<g class = "wave1">
<use xlink:href = "#wave-path" x = "50" y = "3" fill = "rgba(255,255,255, .1)">
</g>
<g class = "wave2">
<use xlink:href = "#wave-path" x = "50" y = "0" fill = "rgba(255,255,255, .2)">
</g>
<g class = "wave3">
<use xlink:href = "#wave-path" x = "50" y = "9" fill = "#fff">
</g>
</svg>
</div>