gpt4 book ai didi

javascript - 基于动画 SVG 定位 SVG

转载 作者:行者123 更新时间:2023-11-28 14:58:20 29 4
gpt4 key购买 nike

我正在尝试制作 submarine (SVG) 看起来好像漂浮在波浪(也是 SVG)。

由于波浪不断上下,我希望潜艇垂直居中 (x),但在波浪顶部水平移动。

这是wave的代码

// best seen at 1500px or less

html, body { height: 100%; }
body {
background:radial-gradient(ellipse at center, rgba(255,254,234,1) 0%, rgba(255,254,234,1) 35%, #B7E8EB 100%);
overflow: hidden;
}

.ocean {
height: 5%;
width:100%;
position:absolute;
bottom:0;
left:0;
background: #015871;
}

.wave {
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/85486/wave.svg) repeat-x;
position: absolute;
top: -198px;
width: 6400px;
height: 198px;
animation: wave 7s cubic-bezier( 0.36, 0.45, 0.63, 0.53) infinite;
transform: translate3d(0, 0, 0);
}

.wave:nth-of-type(2) {
top: -175px;
animation: wave 7s cubic-bezier( 0.36, 0.45, 0.63, 0.53) -.125s infinite, swell 7s ease -1.25s infinite;
opacity: 1;
}

@keyframes wave {
0% {
margin-left: 0;
}
100% {
margin-left: -1600px;
}
}

@keyframes swell {
0%, 100% {
transform: translate3d(0,-25px,0);
}
50% {
transform: translate3d(0,5px,0);
}
}
<div class="ocean">
<div class="wave"></div>
<div class="wave"></div>
</div>

最佳答案

我添加了一个名为“sub”的类来设置您的图片格式并添加动画。请注意,我添加了“缓出”作为动画计时功能,以便它下降得快但上升得慢以跟上波浪计时。但这也只是调整参数和动画“上下”恰到好处的结果,以便它根据它的开始方式在与波浪相反的方向上工作。这是一种方法,如果您想调整高度或缓出,只需更改“子”类中缓出的秒数或调整 updown 函数中的像素数。希望这对您有所帮助!

// best seen at 1500px or less



html, body { height: 100%; }
body {
background:radial-gradient(ellipse at center, rgba(255,254,234,1) 0%, rgba(255,254,234,1) 35%, #B7E8EB 100%);
overflow: hidden;
}


.sub{
position: absolute;
top: 85%;
left: 50%;
width: 100px;
height: 100px;
margin-top: -100px; /* Start height margin */
margin-left: -50px; /* Half the width */
animation: updown 7s cubic-bezier(0.42, 0, 0.58, 1) infinite;
animation-timing-function:ease-in-out;
transform: translate3d(0, 0, 0);
}

.ocean {
height: 5%;
width:100%;
position:absolute;
bottom:0;
left:0;
background: #015871;
}

.wave {
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/85486/wave.svg) repeat-x;
position: absolute;
top: -198px;
width: 6400px;
height: 198px;
animation: wave 7s cubic-bezier(0.36, 0.48, 0.63, 0.53) infinite;
transform: translate3d(0, 0, 0);
}

.wave:nth-of-type(2) {
top: -175px;
animation: wave 7s cubic-bezier( 0.36, 0.45, 0.63, 0.53) -.125s infinite,
swell 7s ease -1.25s infinite;
opacity: 1;
}

@keyframes wave {
0% {
margin-left: 0;
}
100% {
margin-left: -1600px;
}
}

@keyframes swell {
0%, 100% {
transform: translate3d(0,-25px,0);
}
50% {
transform: translate3d(0,5px,0);
}
}

@keyframes updown {
0%, 100% {
transform: translate3d(0,-40px,0);
}
70% {
transform: translate3d(0,45px,0);
}
}
<img class = "sub" src = "https://image.flaticon.com/icons/svg/447/447773.svg">
<div class="ocean">
<div class="wave"></div>
<div class="wave"></div>
</div>

关于javascript - 基于动画 SVG 定位 SVG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50632153/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com