简体   繁体   中英

Switching “d” value in svg path using javascript?

I'm trying to switch out the "d" value and replace it with a dynamically generated number, but I keep getting "unexpected number" as my output. Here's what I currently have:

<path id="pathA" d="M 0 0 l 0 255" stroke="none" stroke-width="0" fill="none"/>

<script>
var sink = document.getElementById("pathA");
sink.setAttribute("d", M 0 0 l 0 (round*25.5));
</script>

Your script as presented has two problems.

First, The second argument you're passing to the setAttribute is not correct. Try:

sink.setAttribute("d", "M 0 0 1 0 " + (round * 25.5));

Second, you don't provide a value for round at any point.

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