gpt4 book ai didi

html - 将 svg 调整为页面宽度

转载 作者:太空宇宙 更新时间:2023-11-03 19:29:55 24 4
gpt4 key购买 nike

有没有办法拉伸(stretch) svg 动画以适合设备的整个屏幕。我想显示以下 svg 动画的两个实例,以便每个都填充屏幕宽度的一半。有没有办法重新定位 View 框的 svg ?

jsFiddle- https://jsfiddle.net/8omxq2qp/

<svg viewBox="0 0 3387 1270">
<path id="planePath" class="planePath" d="M-226 626c439,4 636,-213 934,-225 755,-31 602,769 1334,658 562,-86 668,-698 266,-908 -401,-210 -893,189 -632,630 260,441 747,121 1051,91 360,-36 889,179 889,179" />
<g id="plane" transform="translate(-248,-306)">
<path id="note" fill="F23B3B" transform="translate(0,0)" d="M248.8,306.8c0,0-24-7-28.5,11c0,0-3,16,21,16.5c0,0,19.5,2.3,18.5-28.8s0-61.2,0-61.2s42,9,19,31.5c0,0,17-1,13.5-23c0,0-7.5-20-43-22L248.8,306.8z" />
</g>
<!-- Define the motion path animation -->
<animateMotion xlink:href="#plane" dur="25s" repeatCount="indefinite" rotate="auto">
<mpath xlink:href="#planePath" />
</animateMotion >
</svg>

CSS

html {background-color: #28505D;}

#plane {position: absolute;top: 20%;}

.planePath {stroke: #D9DADA;stroke-width: .1%;stroke-width: .5%;stroke-dasharray: 1% 2%;stroke-linecap: round;fill: none;}

.fil1 {fill: #D9DADA;}

.fil2 {fill: #C5C6C6;}

.fil4 {fill: #9D9E9E;}

.fil3 {fill: #AEAFB0;}

最佳答案

我希望这可以帮助回答您的问题:

请注意,我将 SVG 代码包装在 HTML 文件中具有“响应式”类的 div 中。当多次使用同一个 SVG 时,您只需要更改您可能希望更改的图形的 ID 名称...例如请注意我添加的#plane2 和#plane3 持续时间的变化。然后删除 .svg 和 #plane 定义并添加 .half-responsive 和 .full-responsive 定义,使 svg 响应 CSS 文件中的各种屏幕尺寸。

html {
background-color: #28505D;
}

.planePath {
stroke: #D9DADA;
stroke-width: .1%;
stroke-width: .5%;
stroke-dasharray: 1% 2%;
stroke-linecap: round;
fill: none;
}

.fil1 {
fill: #D9DADA;
}

.fil2 {
fill: #C5C6C6;
}

.fil4 {
fill: #9D9E9E;
}

.fil3 {
fill: #AEAFB0;
}

.half-responsive {
width: 50%;
float: left;
}

.full-responsive {
width: 100%;
float: left;
}
<!DOCTYPE html>
<html lang="en_us">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="author" content="Franciscus Agnew">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Responsive SVG Animation</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
<div class="half-responsive">
<svg viewBox="0 0 3387 1270">
<path id="planePath" class="planePath" d="M-226 626c439,4 636,-213 934,-225 755,-31 602,769 1334,658 562,-86 668,-698 266,-908 -401,-210 -893,189 -632,630 260,441 747,121 1051,91 360,-36 889,179 889,179" />
<g id="plane" transform="translate(-248,-306)">
<path id="note" fill="F23B3B" transform="translate(0,0)" d="M248.8,306.8c0,0-24-7-28.5,11c0,0-3,16,21,16.5c0,0,19.5,2.3,18.5-28.8s0-61.2,0-61.2s42,9,19,31.5c0,0,17-1,13.5-23c0,0-7.5-20-43-22L248.8,306.8z" />
</g>

<!-- Define the motion path animation -->
<animateMotion xlink:href="#plane" dur="25s" repeatCount="indefinite" rotate="auto">
<mpath xlink:href="#planePath" />
</animateMotion>
</svg>
</div>

<div class="half-responsive">
<svg viewBox="0 0 3387 1270">
<path id="planePath" class="planePath" d="M-226 626c439,4 636,-213 934,-225 755,-31 602,769 1334,658 562,-86 668,-698 266,-908 -401,-210 -893,189 -632,630 260,441 747,121 1051,91 360,-36 889,179 889,179" />
<g id="plane2" transform="translate(-248,-306)">
<path id="note" fill="F23B3B" transform="translate(0,0)" d="M248.8,306.8c0,0-24-7-28.5,11c0,0-3,16,21,16.5c0,0,19.5,2.3,18.5-28.8s0-61.2,0-61.2s42,9,19,31.5c0,0,17-1,13.5-23c0,0-7.5-20-43-22L248.8,306.8z" />
</g>

<!-- Define the motion path animation -->
<animateMotion xlink:href="#plane2" dur="50s" repeatCount="indefinite" rotate="auto">
<mpath xlink:href="#planePath" />
</animateMotion>
</svg>
</div>

<div class="full-responsive">
<svg viewBox="0 0 3387 1270">
<path id="planePath" class="planePath" d="M-226 626c439,4 636,-213 934,-225 755,-31 602,769 1334,658 562,-86 668,-698 266,-908 -401,-210 -893,189 -632,630 260,441 747,121 1051,91 360,-36 889,179 889,179" />
<g id="plane3" transform="translate(-248,-306)">
<path id="note" fill="F23B3B" transform="translate(0,0)" d="M248.8,306.8c0,0-24-7-28.5,11c0,0-3,16,21,16.5c0,0,19.5,2.3,18.5-28.8s0-61.2,0-61.2s42,9,19,31.5c0,0,17-1,13.5-23c0,0-7.5-20-43-22L248.8,306.8z" />
</g>

<!-- Define the motion path animation -->
<animateMotion xlink:href="#plane3" dur="80s" repeatCount="indefinite" rotate="auto">
<mpath xlink:href="#planePath" />
</animateMotion>
</svg>
</div>
</body>

</html>

或者,Adobe Animate CC对于涉及为多种屏幕尺寸设置动画 SVG 内容的工作,这将是一个巨大的帮助。

干杯!

关于html - 将 svg 调整为页面宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34775146/

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