svg.draw.js icon indicating copy to clipboard operation
svg.draw.js copied to clipboard

How can we draw on existing SVG?

Open dani2819 opened this issue 8 years ago • 3 comments

I draw a line on svg, now i have a button, on its click function i put a following logic: var draw = SVG(document.getElementById('drawing')).size('100%', '100%'); var polyline = draw.polyline(); polyline.fill('none').stroke({ 'color':'red', 'linecap':'round' }).draw();

The same logic is in window onload function, which executed successfully and we can draw a polyline. But when i clicked on button i want to re-initialize this i can draw another polyline on this svg but i cant.

dani2819 avatar Aug 15 '17 07:08 dani2819

I see no issue with the code. It should work this way

Fuzzyma avatar Aug 15 '17 08:08 Fuzzyma

<script type="text/javascript"> var polyline; var draw; window.onload = function() { var element = document.getElementById('drawing'); draw = SVG(element).size('100%', '100%'); polyline = draw.polyline(); polyline.fill('none').stroke({ 'color':'red', 'linecap':'round' }).draw(); element.addEventListener('mousedown', function(event){ //if right click then fire done event if(event.which==3){ polyline.draw('done');} }); }; //end window.load function drawagain(){ draw = SVG(document.getElementById('drawing')).size('100%', '100%'); polyline = draw.polyline(); polyline.fill('none').stroke({ 'color':'red', 'linecap':'round' }).draw(); } </script>

dani2819 avatar Aug 15 '17 08:08 dani2819

The above one is the whole code, When you click on button then function drawagain() executed.

dani2819 avatar Aug 15 '17 08:08 dani2819