【问题标题】:Animate filling in an SVG cloud icon from left to right从左到右填充 SVG 云图标的动画
【发布时间】:2017-04-20 13:53:14
【问题描述】:

我正在尝试使用 SVG 云动画从左到右填充云(有点像进度条)。这是云:

  %svg{:height => "80", :version => "1.1", :viewbox => "0 0 120 80", :width => "120", :xmlns => "http://www.w3.org/2000/svg", "xmlns:figma" => "http://www.figma.com/figma/ns", "xmlns:xlink" => "http://www.w3.org/1999/xlink"}
    %title Vector
    %g#Canvas{"figma:type" => "canvas", :transform => "translate(1558 -2264)"}
      %g#Vector{"figma:type" => "vector", :style => "mix-blend-mode:normal;"}
        %use{:style => "mix-blend-mode:normal;", :transform => "translate(-1558 2264)", "xlink:href" => "#path0_fill"}
        %use{:fill => "#FFFFFF", :style => "mix-blend-mode:normal;", :transform => "translate(-1558 2264)", "xlink:href" => "#path0_fill"}
    %defs
      %path#path0_fill{:d => "M 96.775 30.175C 93.375 12.975 78.2 0 60 

我尝试创建动画渐变,但这并没有真正奏效。有谁知道我如何为这个 SVG 的轮廓设置动画,在给定的持续时间内从左到右填充?我愿意使用 CSS 或 JS 来实现它。

谢谢。

更新

我相信我想通了,但是当页面加载一半时,云已经加载了一半。

%svg{:height => "104", :version => "1.1", :viewbox => "0 0 144 104", :width => "144", :xmlns => "http://www.w3.org/2000/svg", "xmlns:figma" => "http://www.figma.com/figma/ns", "xmlns:xlink" => "http://www.w3.org/1999/xlink"}
  %g#Canvas{"figma:type" => "canvas", :transform => "translate(1570 -2256)"}
    %g#ic_cloud_48px{"figma:type" => "frame", :filter => "url(#filter0_d)", :style => "mix-blend-mode:normal;"}
      %g#Vector{"figma:type" => "vector", :style => "mix-blend-mode:normal;"}
        %use{:fill => "#ffffff", opacity: '1', :style => "mix-blend-mode:normal;", :transform => "translate(-1558 2264)", "xlink:href" => "#path0_fill"}
  %defs
    %lineargradient#half_grad{x1: 0}
      %stop{:offset => "50%", "stop-color" => "white"}
      %stop{:offset => "50%", "stop-opacity" => "0"}
      %animate{:attributename => "x1", :dur => "60s", :from => "-100%", :to => "100%", fill: "freeze"}

    %filter#filter0_d{"color-interpolation-filters" => "sRGB", :filterunits => "userSpaceOnUse", :height => "104", :width => "144", :x => "-1570", :y => "2256"}
      %feflood{"flood-opacity" => "0", :result => "BackgroundImageFix"}
      %desc type="dropShadow" x="0" y="4" size="12" spread="0" color="0,0.498652,0.660377,0.24" blend="normal"
      %fecolormatrix{:in => "SourceAlpha", :type => "matrix", :values => "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 0"}
      %feoffset{:dx => "0", :dy => "4"}
      %fegaussianblur{:stddeviation => "6"}
      %fecolormatrix{:type => "matrix", :values => "0 0 0 0 0 0 0 0 0 0.498652 0 0 0 0 0.660377 0 0 0 0.24 0"}
      %feblend{:in2 => "BackgroundImageFix", :mode => "normal", :result => "effect1_dropShadow"}
      %feblend{:in => "SourceGraphic", :in2 => "effect1_dropShadow", :mode => "normal", :result => "shape"}
    %path#path0_fill{fill: "url(#half_grad)", 'stroke-width' => "3", stroke: "white", :d => "M 96.775 30.175C 93.375 12.975 78.2 0 60 0C 45.55 0 33.025 8.2 26.75 20.175C 11.725 21.8 0 34.525 0 50C 0 66.575 13.425 80 30 80L 95 80C 108.8 80 120 68.8 120 55C 120 41.8 109.725 31.1 96.775 30.175Z"}

【问题讨论】:

    标签: css animation svg


    【解决方案1】:

    你的错误在于你的线性渐变和你如何动画它。

    %lineargradient#half_grad{x1: 0}
      %stop{:offset => "50%", "stop-color" => "white"}
      %stop{:offset => "50%", "stop-opacity" => "0"}
      %animate{:attributename => "x1", :dur => "60s", :from => "-100%", :to => "100%", fill: "freeze"}
    

    您正在为渐变的x1 设置动画,最高可达 100%,但您的渐变被定义为在中途更改(50%)。如果您希望 50% 的颜色变化与云的右侧重合,则应设置高达 200% 的动画。

    即。以下是(可能)您想要的:

    %animate{:attributename => "x1", :dur => "60s", :from => "0%", :to => "200%", fill: "freeze"}
    

    【讨论】:

    • 谢谢。我想要做的是慢慢地用白色从左到右填充 SVG,因此 50% 的偏移量。是否应该将偏移量设置为其他值以实现此效果?
    • 50% 应该可以。这只是意味着要让你的颜色切换在右侧完成 (100%),你需要 x1 来动画到 200%
    猜你喜欢
    • 1970-01-01
    • 2019-03-06
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-10
    • 2018-09-29
    相关资源
    最近更新 更多