CSS transition animation is not applied on inline svg but on it works fine?

Multi tool use
Multi tool use












0















If you click the button it changes the position on both elements but only the rect has the animation.






function myFunction() {
document.getElementById("stackerCurrentSectBorder").setAttribute("y", "0%")
document.getElementById("stackerCurrentSectCurrShift").setAttribute("y", "10%")
}

#stackerCurrentSect * {
transition: .5s ease;
}

<svg id="statusBoardSVG" ref="statusBoardSVG" viewBox="0 0 500 300" xmlns="http://www.w3.org/2000/svg">
<g id="stackerCurrentSect" ref="stackerCurrentSect">
<rect x="30%" y="30%" width="31%" height="45%" rx="20" ry="20" fill="black" stroke="rgb(200,50,50)" stroke-width="1px" id="stackerCurrentSectBorder" ref="stackerCurrentSectBorder" />
<text x="50%" y="50%" fill="rgb(120,120,120)" alignment-baseline="baseline" text-anchor="middle" font-size="80%" id="stackerCurrentSectCurrShift" ref="stackerCurrentSectCurrShift">current shift</text>
</g>
</svg>

<button onclick="myFunction()">Click me</button>

<p id="demo"></p>












share|improve this question





























    0















    If you click the button it changes the position on both elements but only the rect has the animation.






    function myFunction() {
    document.getElementById("stackerCurrentSectBorder").setAttribute("y", "0%")
    document.getElementById("stackerCurrentSectCurrShift").setAttribute("y", "10%")
    }

    #stackerCurrentSect * {
    transition: .5s ease;
    }

    <svg id="statusBoardSVG" ref="statusBoardSVG" viewBox="0 0 500 300" xmlns="http://www.w3.org/2000/svg">
    <g id="stackerCurrentSect" ref="stackerCurrentSect">
    <rect x="30%" y="30%" width="31%" height="45%" rx="20" ry="20" fill="black" stroke="rgb(200,50,50)" stroke-width="1px" id="stackerCurrentSectBorder" ref="stackerCurrentSectBorder" />
    <text x="50%" y="50%" fill="rgb(120,120,120)" alignment-baseline="baseline" text-anchor="middle" font-size="80%" id="stackerCurrentSectCurrShift" ref="stackerCurrentSectCurrShift">current shift</text>
    </g>
    </svg>

    <button onclick="myFunction()">Click me</button>

    <p id="demo"></p>












    share|improve this question



























      0












      0








      0








      If you click the button it changes the position on both elements but only the rect has the animation.






      function myFunction() {
      document.getElementById("stackerCurrentSectBorder").setAttribute("y", "0%")
      document.getElementById("stackerCurrentSectCurrShift").setAttribute("y", "10%")
      }

      #stackerCurrentSect * {
      transition: .5s ease;
      }

      <svg id="statusBoardSVG" ref="statusBoardSVG" viewBox="0 0 500 300" xmlns="http://www.w3.org/2000/svg">
      <g id="stackerCurrentSect" ref="stackerCurrentSect">
      <rect x="30%" y="30%" width="31%" height="45%" rx="20" ry="20" fill="black" stroke="rgb(200,50,50)" stroke-width="1px" id="stackerCurrentSectBorder" ref="stackerCurrentSectBorder" />
      <text x="50%" y="50%" fill="rgb(120,120,120)" alignment-baseline="baseline" text-anchor="middle" font-size="80%" id="stackerCurrentSectCurrShift" ref="stackerCurrentSectCurrShift">current shift</text>
      </g>
      </svg>

      <button onclick="myFunction()">Click me</button>

      <p id="demo"></p>












      share|improve this question
















      If you click the button it changes the position on both elements but only the rect has the animation.






      function myFunction() {
      document.getElementById("stackerCurrentSectBorder").setAttribute("y", "0%")
      document.getElementById("stackerCurrentSectCurrShift").setAttribute("y", "10%")
      }

      #stackerCurrentSect * {
      transition: .5s ease;
      }

      <svg id="statusBoardSVG" ref="statusBoardSVG" viewBox="0 0 500 300" xmlns="http://www.w3.org/2000/svg">
      <g id="stackerCurrentSect" ref="stackerCurrentSect">
      <rect x="30%" y="30%" width="31%" height="45%" rx="20" ry="20" fill="black" stroke="rgb(200,50,50)" stroke-width="1px" id="stackerCurrentSectBorder" ref="stackerCurrentSectBorder" />
      <text x="50%" y="50%" fill="rgb(120,120,120)" alignment-baseline="baseline" text-anchor="middle" font-size="80%" id="stackerCurrentSectCurrShift" ref="stackerCurrentSectCurrShift">current shift</text>
      </g>
      </svg>

      <button onclick="myFunction()">Click me</button>

      <p id="demo"></p>








      function myFunction() {
      document.getElementById("stackerCurrentSectBorder").setAttribute("y", "0%")
      document.getElementById("stackerCurrentSectCurrShift").setAttribute("y", "10%")
      }

      #stackerCurrentSect * {
      transition: .5s ease;
      }

      <svg id="statusBoardSVG" ref="statusBoardSVG" viewBox="0 0 500 300" xmlns="http://www.w3.org/2000/svg">
      <g id="stackerCurrentSect" ref="stackerCurrentSect">
      <rect x="30%" y="30%" width="31%" height="45%" rx="20" ry="20" fill="black" stroke="rgb(200,50,50)" stroke-width="1px" id="stackerCurrentSectBorder" ref="stackerCurrentSectBorder" />
      <text x="50%" y="50%" fill="rgb(120,120,120)" alignment-baseline="baseline" text-anchor="middle" font-size="80%" id="stackerCurrentSectCurrShift" ref="stackerCurrentSectCurrShift">current shift</text>
      </g>
      </svg>

      <button onclick="myFunction()">Click me</button>

      <p id="demo"></p>





      function myFunction() {
      document.getElementById("stackerCurrentSectBorder").setAttribute("y", "0%")
      document.getElementById("stackerCurrentSectCurrShift").setAttribute("y", "10%")
      }

      #stackerCurrentSect * {
      transition: .5s ease;
      }

      <svg id="statusBoardSVG" ref="statusBoardSVG" viewBox="0 0 500 300" xmlns="http://www.w3.org/2000/svg">
      <g id="stackerCurrentSect" ref="stackerCurrentSect">
      <rect x="30%" y="30%" width="31%" height="45%" rx="20" ry="20" fill="black" stroke="rgb(200,50,50)" stroke-width="1px" id="stackerCurrentSectBorder" ref="stackerCurrentSectBorder" />
      <text x="50%" y="50%" fill="rgb(120,120,120)" alignment-baseline="baseline" text-anchor="middle" font-size="80%" id="stackerCurrentSectCurrShift" ref="stackerCurrentSectCurrShift">current shift</text>
      </g>
      </svg>

      <button onclick="myFunction()">Click me</button>

      <p id="demo"></p>






      javascript html css animation svg






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 20:48









      chazsolo

      5,2021233




      5,2021233










      asked Nov 23 '18 at 20:39









      ChaseQChaseQ

      122




      122
























          1 Answer
          1






          active

          oldest

          votes


















          0














          To use a CSS transition, you need a CSS property to animate. The <text> x and y attributes are not. (Mainly, because they can take a list of values that position glyphs individually.)



          In addition, x and y for the <rect> element have only been defined as CSS properties in the SVG 2 spec, which isn't yet fully implemented by all browsers.



          You can easily use a transform property instead. But you must set the style property, not the attribute, because the attribute does not take unit identifiers (yet):






          function myFunction() {
          document.getElementById("stackerCurrentSectBorder").style.transform = "translateY(-30%)"
          document.getElementById("stackerCurrentSectCurrShift").style.transform = "translateY(-40%)"
          }

          #stackerCurrentSect * {
          transition: .5s ease;
          }

          <svg id="statusBoardSVG" ref="statusBoardSVG" viewBox="0 0 500 300" xmlns="http://www.w3.org/2000/svg">
          <g id="stackerCurrentSect" ref="stackerCurrentSect">
          <rect x="30%" y="30%" width="31%" height="45%" rx="20" ry="20" fill="black" stroke="rgb(200,50,50)" stroke-width="1px" id="stackerCurrentSectBorder" ref="stackerCurrentSectBorder" />
          <text x="50%" y="50%" fill="rgb(120,120,120)" alignment-baseline="baseline" text-anchor="middle" font-size="80%" id="stackerCurrentSectCurrShift" ref="stackerCurrentSectCurrShift">current shift</text>
          </g>
          </svg>

          <button onclick="myFunction()">Click me</button>

          <p id="demo"></p>








          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452708%2fcss-transition-animation-is-not-applied-on-inline-svg-text-but-on-rect-it-wo%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            To use a CSS transition, you need a CSS property to animate. The <text> x and y attributes are not. (Mainly, because they can take a list of values that position glyphs individually.)



            In addition, x and y for the <rect> element have only been defined as CSS properties in the SVG 2 spec, which isn't yet fully implemented by all browsers.



            You can easily use a transform property instead. But you must set the style property, not the attribute, because the attribute does not take unit identifiers (yet):






            function myFunction() {
            document.getElementById("stackerCurrentSectBorder").style.transform = "translateY(-30%)"
            document.getElementById("stackerCurrentSectCurrShift").style.transform = "translateY(-40%)"
            }

            #stackerCurrentSect * {
            transition: .5s ease;
            }

            <svg id="statusBoardSVG" ref="statusBoardSVG" viewBox="0 0 500 300" xmlns="http://www.w3.org/2000/svg">
            <g id="stackerCurrentSect" ref="stackerCurrentSect">
            <rect x="30%" y="30%" width="31%" height="45%" rx="20" ry="20" fill="black" stroke="rgb(200,50,50)" stroke-width="1px" id="stackerCurrentSectBorder" ref="stackerCurrentSectBorder" />
            <text x="50%" y="50%" fill="rgb(120,120,120)" alignment-baseline="baseline" text-anchor="middle" font-size="80%" id="stackerCurrentSectCurrShift" ref="stackerCurrentSectCurrShift">current shift</text>
            </g>
            </svg>

            <button onclick="myFunction()">Click me</button>

            <p id="demo"></p>








            share|improve this answer




























              0














              To use a CSS transition, you need a CSS property to animate. The <text> x and y attributes are not. (Mainly, because they can take a list of values that position glyphs individually.)



              In addition, x and y for the <rect> element have only been defined as CSS properties in the SVG 2 spec, which isn't yet fully implemented by all browsers.



              You can easily use a transform property instead. But you must set the style property, not the attribute, because the attribute does not take unit identifiers (yet):






              function myFunction() {
              document.getElementById("stackerCurrentSectBorder").style.transform = "translateY(-30%)"
              document.getElementById("stackerCurrentSectCurrShift").style.transform = "translateY(-40%)"
              }

              #stackerCurrentSect * {
              transition: .5s ease;
              }

              <svg id="statusBoardSVG" ref="statusBoardSVG" viewBox="0 0 500 300" xmlns="http://www.w3.org/2000/svg">
              <g id="stackerCurrentSect" ref="stackerCurrentSect">
              <rect x="30%" y="30%" width="31%" height="45%" rx="20" ry="20" fill="black" stroke="rgb(200,50,50)" stroke-width="1px" id="stackerCurrentSectBorder" ref="stackerCurrentSectBorder" />
              <text x="50%" y="50%" fill="rgb(120,120,120)" alignment-baseline="baseline" text-anchor="middle" font-size="80%" id="stackerCurrentSectCurrShift" ref="stackerCurrentSectCurrShift">current shift</text>
              </g>
              </svg>

              <button onclick="myFunction()">Click me</button>

              <p id="demo"></p>








              share|improve this answer


























                0












                0








                0







                To use a CSS transition, you need a CSS property to animate. The <text> x and y attributes are not. (Mainly, because they can take a list of values that position glyphs individually.)



                In addition, x and y for the <rect> element have only been defined as CSS properties in the SVG 2 spec, which isn't yet fully implemented by all browsers.



                You can easily use a transform property instead. But you must set the style property, not the attribute, because the attribute does not take unit identifiers (yet):






                function myFunction() {
                document.getElementById("stackerCurrentSectBorder").style.transform = "translateY(-30%)"
                document.getElementById("stackerCurrentSectCurrShift").style.transform = "translateY(-40%)"
                }

                #stackerCurrentSect * {
                transition: .5s ease;
                }

                <svg id="statusBoardSVG" ref="statusBoardSVG" viewBox="0 0 500 300" xmlns="http://www.w3.org/2000/svg">
                <g id="stackerCurrentSect" ref="stackerCurrentSect">
                <rect x="30%" y="30%" width="31%" height="45%" rx="20" ry="20" fill="black" stroke="rgb(200,50,50)" stroke-width="1px" id="stackerCurrentSectBorder" ref="stackerCurrentSectBorder" />
                <text x="50%" y="50%" fill="rgb(120,120,120)" alignment-baseline="baseline" text-anchor="middle" font-size="80%" id="stackerCurrentSectCurrShift" ref="stackerCurrentSectCurrShift">current shift</text>
                </g>
                </svg>

                <button onclick="myFunction()">Click me</button>

                <p id="demo"></p>








                share|improve this answer













                To use a CSS transition, you need a CSS property to animate. The <text> x and y attributes are not. (Mainly, because they can take a list of values that position glyphs individually.)



                In addition, x and y for the <rect> element have only been defined as CSS properties in the SVG 2 spec, which isn't yet fully implemented by all browsers.



                You can easily use a transform property instead. But you must set the style property, not the attribute, because the attribute does not take unit identifiers (yet):






                function myFunction() {
                document.getElementById("stackerCurrentSectBorder").style.transform = "translateY(-30%)"
                document.getElementById("stackerCurrentSectCurrShift").style.transform = "translateY(-40%)"
                }

                #stackerCurrentSect * {
                transition: .5s ease;
                }

                <svg id="statusBoardSVG" ref="statusBoardSVG" viewBox="0 0 500 300" xmlns="http://www.w3.org/2000/svg">
                <g id="stackerCurrentSect" ref="stackerCurrentSect">
                <rect x="30%" y="30%" width="31%" height="45%" rx="20" ry="20" fill="black" stroke="rgb(200,50,50)" stroke-width="1px" id="stackerCurrentSectBorder" ref="stackerCurrentSectBorder" />
                <text x="50%" y="50%" fill="rgb(120,120,120)" alignment-baseline="baseline" text-anchor="middle" font-size="80%" id="stackerCurrentSectCurrShift" ref="stackerCurrentSectCurrShift">current shift</text>
                </g>
                </svg>

                <button onclick="myFunction()">Click me</button>

                <p id="demo"></p>








                function myFunction() {
                document.getElementById("stackerCurrentSectBorder").style.transform = "translateY(-30%)"
                document.getElementById("stackerCurrentSectCurrShift").style.transform = "translateY(-40%)"
                }

                #stackerCurrentSect * {
                transition: .5s ease;
                }

                <svg id="statusBoardSVG" ref="statusBoardSVG" viewBox="0 0 500 300" xmlns="http://www.w3.org/2000/svg">
                <g id="stackerCurrentSect" ref="stackerCurrentSect">
                <rect x="30%" y="30%" width="31%" height="45%" rx="20" ry="20" fill="black" stroke="rgb(200,50,50)" stroke-width="1px" id="stackerCurrentSectBorder" ref="stackerCurrentSectBorder" />
                <text x="50%" y="50%" fill="rgb(120,120,120)" alignment-baseline="baseline" text-anchor="middle" font-size="80%" id="stackerCurrentSectCurrShift" ref="stackerCurrentSectCurrShift">current shift</text>
                </g>
                </svg>

                <button onclick="myFunction()">Click me</button>

                <p id="demo"></p>





                function myFunction() {
                document.getElementById("stackerCurrentSectBorder").style.transform = "translateY(-30%)"
                document.getElementById("stackerCurrentSectCurrShift").style.transform = "translateY(-40%)"
                }

                #stackerCurrentSect * {
                transition: .5s ease;
                }

                <svg id="statusBoardSVG" ref="statusBoardSVG" viewBox="0 0 500 300" xmlns="http://www.w3.org/2000/svg">
                <g id="stackerCurrentSect" ref="stackerCurrentSect">
                <rect x="30%" y="30%" width="31%" height="45%" rx="20" ry="20" fill="black" stroke="rgb(200,50,50)" stroke-width="1px" id="stackerCurrentSectBorder" ref="stackerCurrentSectBorder" />
                <text x="50%" y="50%" fill="rgb(120,120,120)" alignment-baseline="baseline" text-anchor="middle" font-size="80%" id="stackerCurrentSectCurrShift" ref="stackerCurrentSectCurrShift">current shift</text>
                </g>
                </svg>

                <button onclick="myFunction()">Click me</button>

                <p id="demo"></p>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 '18 at 21:05









                ccprogccprog

                9,23521027




                9,23521027






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452708%2fcss-transition-animation-is-not-applied-on-inline-svg-text-but-on-rect-it-wo%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    nfk355H,BYPuk,xnLJVexHexXR,N,yVnPc6BkBGH9TyZw8Aq99P8R,Zq,E7,gPIzmJZzr38
                    xm1CPfB,7,986 swGBAIVUME7 pK5rawoRZS

                    Popular posts from this blog

                    xlwings: Save and Close

                    Logiciel libre

                    UPSERT syntax error linked to UPDATE in PostgreSQL (python)