简体   繁体   中英

Changing parts of SVG-Path on the fly

I'm using RaphaelJS for SVG graphics and I've a path like this:

var path = canvas.path("M50,100 l0,100 c100,-100, 200,100, 300,0");

But later I might want to change some parts of the graph. Eg:

var path = canvas.path("M50,100 l0,100 c100,100, 200,-100, 300,0"); 

Notice the moveTo and lineTo commands are the same solely two arguments for curveTo have changed. Can I change parts of path directly or do I have to draw a new path and delete the old one?

( Fiddle )

Demo: http://jsfiddle.net/dBqya/

function togglePath(path){
    path.attr('path', 'M50,100 l0,100 c100,100, 200,-100, 300,0');
}

var canvas = Raphael('canvas', 500, 500);

var path = canvas.path('M50,100 l0,100 c100,-100, 200,100, 300,0');
path.attr({ stroke: 'red', 'stroke-width': 3 });

document.getElementById('toggle').addEventListener('click', function () { 
  togglePath(path);
});
​

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