简体   繁体   中英

setAttribute(“transform”,…) doesn't work on <symbol> element

I need some helping in svg/javascript programming. I made a SVG Graphic in which the elements "Stern" should rotating by the onmouseover-event . We are not allowed to use the svg-animations and the animation should be done by javascript. My idea is to use setAttribute("transform",...) , but that doesn't work anyway. I google about an hour, but nothing I found there works. The function stern_rotieren is triggered by the mouse (I tested it with alert("test") ) and things like setAttribute("fill","white") works perfectly in the same function. Only setAttribute("transform",...) doesn't work. Maybe you can show me my failure, I'm desperate.

<defs>
    <script type="text/javascript">

        other functions

        function stern_rotieren(){
            var stern=document.getElementById("Stern");
            stern.setAttribute("transform","rotate(15 500 500)");           
        }

    </script>
    <symbol id="Baum" fill="white" stroke="green" stroke-width="5">
        <path d="M 1000,200 Q 950,400 800,500 Q 600,600 750,650 T 700,850" />
        <path d="M 700,850 Q 400,1100 600, 1100 T 500,1400" />
        <path d="M 500,1400 Q 250,1600 450,1600 L 850,1600 Q 950,1600 950,1700" />
    </symbol>
    <symbol id="Kugel" fill="red" onclick="kugel_farbe()" transform="translate(0,0)">
        <circle cx="50" cy="50" r="50" />
    </symbol>
    <symbol id="Stern" fill="yellow" onclick="stern_farbe()" onmouseover="stern_rotieren()" >
        <polygon points="200,20 80,360 380,120 20,120 320,360"/>
    </symbol>
</defs>

<use xlink:href="#Baum" transform="translate(0,250)" />
<use xlink:href="#Baum" transform="translate(2000,250) scale(-1,1)" />
<use xlink:href="#Kugel" transform="translate(850,1050)" />
<use xlink:href="#Kugel" transform="translate(1050,750)" />
<use xlink:href="#Kugel" transform="translate(1200,1250)" />
<use xlink:href="#Kugel" transform="translate(700,1650)" />
<use xlink:href="#Kugel" transform="translate(1300,1700)" />
<use xlink:href="#Stern" transform="translate(800,185)" />
<use xlink:href="#Stern" transform="translate(970,900) scale(0.5)" />
<use xlink:href="#Stern" transform="translate(800,1300) scale(0.5)" />

symbol elements don't accept a transform attribute. It would work if you set the transform attribute on the child polygon element for instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM