【问题标题】:SVG animation diagonal viewboxSVG动画对角视框
【发布时间】:2019-10-14 02:45:03
【问题描述】:

我希望能够做出这样的设计:

https://www.reddit.com/r/webdev/comments/bromkj/ello_everyone_this_is_a_ui_i_made_in_adobe_xd/

您可以在以下位置找到我的网站:El Paso Texas Graphic Design and Web Design | Desert Sun Studio

它的基本设置是在橙色 HTML 和正文之上的不同 z-index 上放置两个固定的 SVG。

html, body{
  margin: 0;
  padding: 0;
  font-family: "Oxygen", "Arial", sans-serif;
  background-color: #A36D00;
} 

#left-panel{
  position: fixed;
  z-index: 3;
  animation-name: left-panelmove;
  animation-duration: 200ms;
  animation-fill-mode: forwards;
  animation-delay: 500ms;
}

#right-panel{
  position: fixed;
  z-index: 4;
  animation-name: right-panelmove;
  animation-duration: 200ms;
  animation-fill-mode: forwards;
  animation-delay: 500ms;
}

当这个动画运行时,你可以看到 SVG 被屏蔽为一个矩形:

@keyframes right-panelmove {
    from {transform: translate(0, 0);}
    to {transform: translate(15%, 10%);}
}

@keyframes left-panelmove {
    from {transform: translate(0, 0);}
    to {transform: translate(-15%, -10%);}
}

但是你可以看到我的 SVG 上的黑色方块比画板大得多。

我想知道是否可以对这段代码执行任何操作以使 SVG 一直沿对角线在屏幕上运行,特别是到视图框:

<svg version="1.1" id="ab9dac86-5d7c-460b-b35e-9ae3db46aedc"
     xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1920 1080"
     style="enable-background:new 0 0 1920 1080;" xml:space="preserve">

【问题讨论】:

  • 如果这是我。我会重新创建 svg @45 度。使用水平窗帘垂直创建切片,然后在 css 中将动画旋转 45 度到正常角度并制作动画。
  • @DreamTek 你能详细说明一下吗,尝试旋转方形 svg,它不会覆盖一半的屏幕。
  • 你可以让你的黑色形状特别大。然后在 SVG 上设置overflow: visible。只要它们大到足以覆盖典型的屏幕尺寸,黑色就应该到达页面的边缘。
  • @Paul LeBeau 谢谢,这是问题的要点;我正在将我的动画应用到父对象

标签: css animation svg


【解决方案1】:
@keyframes right-panelmove {
    from {transform: translate(0, 0);}
    to {transform: translate(15%, 10%);}
}

@keyframes left-panelmove {
    from {transform: translate(0, 0);}
    to {transform: translate(-15%, -10%);}
}

.left-panelmove{
  animation-name: left-panelmove;
  animation-duration: 200ms;
  animation-fill-mode: forwards;
  animation-delay: 500ms;
}

.right-panelmove{
  animation-name: right-panelmove;
  animation-duration: 200ms;
  animation-fill-mode: forwards;
  animation-delay: 500ms;
}

我将@keyframes 和类移动到 SVG 样式标签内的适当 SVG(左和右),它运行良好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-22
    • 1970-01-01
    • 2016-06-11
    • 2011-12-10
    • 2019-07-30
    • 2013-11-05
    • 2020-01-11
    • 1970-01-01
    相关资源
    最近更新 更多