Teo*_*Teo 6 css 3d svg transform css3
是否可以通过SVG元素的三维变换实现透视?
我正在谈论类似于星球大战开场标题的三维视角.这是一个使用CSS3 3d变换实现所需效果的jsfiddle:
<section style="transform: perspective(200px) rotateX(-30deg); transform-origin: 50% 100%; text-align: justify; width: 100px;">
<p style="backface-visibility: hidden;">TEXTTEXTTEXT</p>
</section>Run Code Online (Sandbox Code Playgroud)
web*_*iki 16
2018年11月更新:
从最新的chrome和Firefox中的问题测试snipet.尽管对svg元素的3d变换的支持不是很广,但浏览器正在越来越多地实现它.
来源答案:
SVG元素不支持3D变换.但有一些解决方法:
如果svg不包含不应转换的元素,则可以在SVG元素本身上使用CSS 3d转换:
svg {
width: 70%;
margin: 0 auto;
display: block;
-webkit-transform: perspective(300px) rotateX(30deg);
transform: perspective(300px) rotateX(30deg);
}Run Code Online (Sandbox Code Playgroud)
<svg viewbox="0 0 100 20">
<text x="0" y="20">TEXTEXTEX</text>
</svg>Run Code Online (Sandbox Code Playgroud)
对于多边形,可以使2D多边形看起来像3D多边形.在以下示例中,红色矩形是3D旋转(rotateX(40deg)),黑色矩形是2D SVG多边形,看起来像3D旋转的矩形:
div{
display:inline-block;
width:200px; height:100px;
background:red;
transform:perspective(500px) rotateX(40deg);
}
svg{
display:inline-block;
width:220px; height:auto;
}
div, svg{
display:inline-block;
margin:0 10px;
}Run Code Online (Sandbox Code Playgroud)
<div></div>
<svg viewbox="0 0.5 10 4">
<polygon points="9.9 4.1 0.1 4.1 0.7 0.6 9.3 0.6" fill=""/>
</svg>Run Code Online (Sandbox Code Playgroud)
元素内部支持 3D 变换<svg>(fe on <circle>)(至少在某种程度上,透视似乎只是等轴测)。
例如,以下是transform: rotate3d应用于<circle>元素的动画(仅在 Chrome 中测试):
body, html {
background: black;
width: 100%; height: 100%;
margin: 0;
padding: 0;
}
body {
display: flex;
}
svg {
width: 100%;
}
.gAExgp {
transform-origin: 50% 50% 0px;
animation-name: phEs, ipaUyp;
animation-duration: 4s, 7s;
animation-timing-function: linear;
animation-iteration-count: infinite;
}
.PwswZ {
transform-origin: 50% 50% 0px;
animation-name: gcRPJT, ipaUyp;
animation-duration: 4s, 8s;
animation-timing-function: linear;
animation-iteration-count: infinite;
}
@keyframes phEs {
50% {
transform: rotate3d(0, 2, 1, 180deg);
}
100% {
transform: rotate3d(0, 2, 1, 360deg);
}
}
@keyframes gcRPJT {
50% {
transform: rotate3d(2, 0, 1, 180deg);
}
100% {
transform: rotate3d(2, 0, 1, 360deg);
}
}
@keyframes ipaUyp {
0% {
stroke: magenta;
}
33% {
stroke: cyan;
}
66% {
stroke: yellow;
}
100% {
stroke: magenta;
}
}Run Code Online (Sandbox Code Playgroud)
<!-- Logo from https://rebassjs.org -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" style="display:block;max-width:100%;margin:0;fill:none;stroke:cyan" vector-effect="non-scaling-stroke" class="sc-htoDjs hCHUAb"><circle cx="32" cy="32" r="32" fill="#000" stroke="none"></circle><circle cx="32" cy="32" r="30" stroke-width="1" vector-effect="non-scaling-stroke" opacity="0.5"></circle><g><circle cx="32" cy="32" r="24" stroke-width="2" vector-effect="non-scaling-stroke" class="sc-dnqmqq gAExgp"></circle><circle cx="32" cy="32" r="24" stroke-width="2" vector-effect="non-scaling-stroke" class="sc-iwsKbI PwswZ"></circle></g><text x="32" y="34" text-anchor="middle" font-family="system-ui, sans-serif" font-weight="bold" font-size="4" stroke="none" fill="white" style="text-transform:uppercase;letter-spacing:0.5em">Rebass</text></svg>Run Code Online (Sandbox Code Playgroud)
也可以在这里找到: https: //codepen.io/anon/pen/MPeyEj
| 归档时间: |
|
| 查看次数: |
9263 次 |
| 最近记录: |