PH.
PH.

Reputation: 596

SVG text upside down when trying to support animation

I am having trouble making the text orientation correct. I tried as suggested on SVG TextPath Text shows upside-down but it makes the animation start from opposite side. I need the animation start from the initial node.

I am doing the animation using stroke-dashoffset and stroke-dasharray. In the code below I have shown various lines that are possible and the the direction is shown with the arrow.

<!DOCTYPE html>
<html>
    <head>
        <style>
            @keyframes dash {
                to   { stroke-dashoffset: 0; }
            }
            path {
                animation: dash 2s linear forwards;
                stroke-dasharray: 1500;
                stroke-dashoffset: 1500;
            }
        </style>
    </head>
    <body>
        <svg width="1580" height="390" viewbox="0 0 1580 790" preserveaspectratio="none">
        <g>
            <g transform="translate(0,80)">
                <g>
                    <path d="M 280 120 300 120 C 702 120, 780 120, 780 120 S 858 120, 1300 120" id="link1" stroke-width="20" fill="none" stroke="#bcb8b8"></path>
                    <text>
                        <textpath xlink:href="#link1" startoffset="10">
                            <tspan dy="5" dx="0">
                                Some Text ->
                            </tspan>
                        </textpath>
                    </text>
                </g>
                <g>
                    <path d="M 1300 170 858 170 C 780 170, 780 170, 702 170 S 300 170, 280 170" id="link2" stroke-width="20" fill="none" stroke="#bcb8b8"></path>
                    <text>
                        <textpath xlink:href="#link2" startoffset="10">
                            <tspan dy="5" dx="0">
                                <- Some Text
                            </tspan>
                        </textpath>
                    </text>
                </g>
                <g>
                    <path d="M 440,330 C 748,330 748,460 440,460" id="link3" stroke-width="20" fill="none" stroke="#bcb8b8"></path>
                    <text>
                        <textPath xlink:href="#link3" startOffset="10">
                            <tspan dy="5" dx="0">
                                Some Text ->
                            </tspan>
                        </textPath>
                    </text>
                </g>
                <g>
                    <path d="M 740,460 C 1048,460 1048,330 740,330" id="link4" stroke-width="20" fill="none" stroke="#bcb8b8"></path>
                    <text>
                        <textPath xlink:href="#link4" startOffset="10">
                            <tspan dy="5" dx="0">
                                Some Text ->
                            </tspan>
                        </textPath>
                    </text>
                </g>
                <g>
                    <path d="M 640,660 C 340,660 340,530 640,530" id="link5" stroke-width="20" fill="none" stroke="#bcb8b8"></path>
                    <text>
                        <textpath xlink:href="#link5" startoffset="10">
                            <tspan dy="5" dx="0">
                                Some Text ->
                            </tspan>
                        </textpath>
                    </text>
                </g>
                <g>
                    <path d="M 950,530 C 650,530 650,660 950,660" id="link6" stroke-width="20" fill="none" stroke="#bcb8b8"></path>
                    <text>
                        <textpath xlink:href="#link6" startoffset="10">
                            <tspan dy="5" dx="0">
                                Some Text ->
                            </tspan>
                        </textpath>
                    </text>
                </g>
            </g>
        </svg>
    </body>
</html>

Upvotes: 1

Views: 145

Answers (1)

enxaneta
enxaneta

Reputation: 33024

My solution is using a reversed path for the text. I've putted the reversed paths in the <defs>. I'm using a golden stroke where I'm using a reversed path. I hope this is what you need.

@keyframes dash {
  to {
    stroke-dashoffset: 0;
  }
}
path {
  animation: dash 2s linear forwards;
  stroke-dasharray: 1500;
  stroke-dashoffset: 1500;
}
svg{border:1px solid}
<svg viewbox="0 0 1580 790">
  <defs>
    <path d="M280,170C300,170 624,170 702,170C780,170 780,170 1300,170" id="reversed2" ></path>
    <path d="M640,530C340,530 340,660 640,660" id="reversed5" />
    <path d="M950,660C650,660 650,530 950,530" id="reversed6" />  
  </defs>
  
        <g>
            <g transform="translate(0,80)">
                <g>
                    <path d="M 280 120 300 120 C 702 120, 780 120, 780 120 S 858 120, 1300 120" id="link1" stroke-width="20" fill="none" stroke="#bcb8b8"></path>
                    <text>
                        <textpath xlink:href="#link1" startoffset="10">
                            <tspan dy="5" dx="0">
                                Some Text ->
                            </tspan>
                        </textpath>
                    </text>
                </g>
                <g>
                    <path d="M 1300 170 C 780 170, 780 170, 702 170 S 300 170, 280 170" id="link2" stroke-width="20" fill="none" stroke="gold"></path>
                  
                  
                    <text>
                        <textpath xlink:href="#reversed2" startoffset="100%" text-anchor="end">
                            <tspan dy="5" dx="0">
                                <- Some Text
                            </tspan>
                        </textpath>
                    </text>
                </g>
                <g>
                    <path d="M 440,330 C 748,330 748,460 440,460" id="link3" stroke-width="20" fill="none" stroke="#bcb8b8"></path>
                    <text>
                        <textPath xlink:href="#link3" startOffset="10">
                            <tspan dy="5" dx="0">
                                Some Text ->
                            </tspan>
                        </textPath>
                    </text>
                </g>
                <g>
                    <path d="M 740,460 C 1048,460 1048,330 740,330" id="link4" stroke-width="20" fill="none" stroke="#bcb8b8"></path>
                    <text>
                        <textPath xlink:href="#link4" startOffset="10">
                            <tspan dy="5" dx="0">
                                Some Text ->
                            </tspan>
                        </textPath>
                    </text>
                </g>
                <g>
                    <path d="M 640,660 C 340,660 340,530 640,530" id="link5" stroke-width="20" fill="none" stroke="gold"></path>
                  
                  
                    <text>
                        <textpath xlink:href="#reversed5" startoffset="100%" text-anchor="end">
                            <tspan dy="5" dx="0">
                                Some Text ->
                            </tspan>
                        </textpath>
                    </text>
                </g>
                <g>
                    <path d="M 950,530 C 650,530 650,660 950,660" id="link6" stroke-width="20" fill="none" stroke="gold"></path>
                    <text>
                        <textpath xlink:href="#reversed6" startoffset="100%" text-anchor="end">
                            <tspan dy="5" dx="0">
                                Some Text ->
                            </tspan>
                        </textpath>
                    </text>
                </g>
            </g>
        </svg>

Upvotes: 1

Related Questions