Search code examples
svgsvg-animate

Starting svg animation on the end of another animation doesn't trigger


I have two svg animations and I want to start #anim-join-gradient animation on the end of #anim-vert-gradient, but #anim-join-gradient animation doesn't start.

#anim-join-gradient element has attribute begin="anim-vert-gradient.end"

.box1{width:25px}
<div class="box box1">
  <svg viewbox="0 0 100 100">
    <path id="button" class="arrow" d="M 50,0 L 60,10 L 20,50 L 60,90 L 50,100 L 0,50 Z" />
  </svg>
</div>

<svg id="play-vert-line" width="110" height="110">
								<defs>
								<linearGradient id="vert-gradient" gradientUnits="userSpaceOnUse" y1="0%" y2="100%" x1="0" x2="0">
									<stop stop-color="#1689fb"></stop>
									<stop stop-color="#7e7e7e"></stop>
									<animate xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#vert-gradient" id="anim-vert-gradient" attributeName="y1" dur="800ms" to="99%" begin="button.click" fill="freeze"></animate>
								</linearGradient>
								</defs>
								<line id="vert-line-1" x1="55.3" y1="0" x2="55.3" y2="105" stroke="url(#vert-gradient)" stroke-width="2"></line>
							</svg>
<svg id="line-join" width="110" height="110">
								<defs>
								<linearGradient id="vert-join-gradient" gradientUnits="userSpaceOnUse" y1="0%" y2="100%" x1="0" x2="0">
									<stop stop-color="#1689fb"></stop>
									<stop stop-color="#7e7e7e"></stop>
									<animate xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#vert-join-gradient" id="anim-join-gradient" attributeName="y1" dur="400ms" from="0%" to="99%" begin="anim-vert-gradient.end" fill="freeze"></animate>
								</linearGradient>
								</defs>
							  <line id="vert-line-2" x1="105" y1="0" x2="105" y2="105" stroke="url(#vert-join-gradient)" stroke-width="2"></line>
							</svg>


Solution

  • minus signs are treated specially in begin attributes. Unescaped minus signs are treated as the subtraction operator. Per the spec you need to escape them if you don't want that e.g.

    begin="anim\-vert\-gradient.end"
    

    That would work on Firefox. Chrome has a bug and doesn't support escaping so if you want it to work there you'd have to remove the - signs.