简体   繁体   中英

What is the difference between absolute and relative SVG path?

I know that capital letter for absolute and lower letter for relative but I don't understand the difference between both of them and when I can use each kind.

For example : This example give me different shapes when i use capital letter and lower one.

<svg height="210" width="400">
    <path d="M150 0 L75 200 L225 200 Z" />
</svg>

With relative (lower case) commands, the coordinates are calculated relative to the endpoint of the last path segment.

So in the case of your path:

M 150 0
L 75 200
L 225 200
Z

the path passes through the coordinates as listed.

However with relative commands you would get the following actual coordinates:

              Actual         How this was calculated
             --------------- --------------------------------------
m 150 0       (150, 0)       (0 + 150, 0 + 0)
l 75 200      (225, 200)     (150 + 75, 0 + 200)     (ie. lastX + thisX, lastY + thisY)
l 225 200     (450, 400)     (225 + 225, 200 + 200)
z                            (Z and z have identical behaviour)

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