【问题标题】:Equivalent of transform3d in SVG transformsSVG 变换中的 transform3d 等价物
【发布时间】:2019-04-26 08:54:13
【问题描述】:

这个问题很好地告诉我,SVG 不支持来自 CSS 的 transform3d3d transforms on SVG element

但回复中的一位评论者建议可以使用 SVG 原生 rotate()scale() 转换的组合来模拟效果。

这是我的演示 SVG:

<svg viewBox="0 0 300 100" xmlns="http://www.w3.org/2000/svg">
  <circle id="circle1" cx="50" cy="50" r="40" stroke="red" fill="grey" />
  <circle id="circle2" cx="150" cy="50" r="4" stroke="red" fill="grey" />
</svg>

是否可以通过修改SVG circle 元素上的transform 属性来模拟将CSS transform3d(1.05, 1.05, 1.05) 应用于#circle1 的效果? transform3dx,y,z 与组合旋转和缩放的 5 个参数之间的数学关系是什么?还是说不可能?

【问题讨论】:

  • 不,这是不可能的。 SVG 变换属性仅支持 2d 变换。

标签: css svg graphics


【解决方案1】:

transform-function 现在可以像在 CSS 中一样工作,但参考资料指出两者之间的语法差异并且可能存在问题,即无法保证。在这个 sn-p 中,将鼠标放在块上以获得 rotate3d 的示例:

    * {
      box-sizing: border-box;
      margin: 0;
      padding: 10;
    }
        
    @keyframes transform {
        from {transform:perspective(800px) rotate3d(1,0,0,-95deg)}
        to {transform:perspective(800px) rotate3d(1,0,0, 0deg)}
    }
        
    #thing:active {
            animation: transform .8s steps(100) both;
            transform-origin: 0% 90%;
    }
    <html>
    <head>
       <link href="seat2.css" rel="stylesheet" />
    </head>
    
    <svg id="thing" xmlns="http://www.w3.org/2000/svg" width="150px" height="150px" viewBox="0 0 150 150">
        <rect width="100" height="100"/>
    </svg>
    </html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-16
    • 2021-11-08
    • 1970-01-01
    • 2019-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多