Answer the question
In order to leave comments, you need to log in
How to draw lines with the mouse in SVG?
Good day everyone. Faced a problem (due to lack of knowledge) in drawing a line with the mouse in SVG. There is the following code:
...
var s = Snap(500, 200);
var line1 = s.line(20, 30, 100, 100);
line1.attr ({
stroke: "black"
});
// Определение координат мыши__________________
var mouse = {
getX: function(e) {
return e.offsetX;
},
getY: function(e) {
return e.offsetY;
}
};
//_____________________________________________
s.mousedown (function (e){
line1.attr({x1: mouse.getX(e)});
line1.attr({y1: mouse.getY(e)});
s.mousemove (function(e){
line1.attr('x2', mouse.getX(e));
line1.attr('y2', mouse.getY(e));
})
})
s.mouseup (function(e){
line1.attr({x2: mouse.getX(e)});
line1.attr({y2: mouse.getY(e)});
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question