There are two lines. The right end of the black line1 can be moved with the mouse. The coordinates of the end of the green line line2 depend on line1 through the moveline2 function.
Then added the animation of the first line by clicking on the red circle. In this case, line1 is animated, and the moveline2 function, which also starts up on this event, is triggered once and that's it. The second line remains without animation, although it is functionally related to the animated first.
It is clear that as the animation goes on, some events should be generated for which you can start redrawing the second line, but how to do it?
How to make all objects move functionally related to the only one on which the animation hangs? I use library svg.js but, probably, it is not basic. Library documentation https://svgdotjs.imtqy.com
var paper = SVG('draw').size('100%', '100%'); var line1 = paper.line(0, 100, 300, 100).stroke({ width: 5 }).style({ cursor: 'pointer' }); var line2 = paper.line(0, 200, 100, 200).stroke({ width: 5 }).attr({ stroke: 'green' }); var circle = paper.circle(30).move(50, 50).fill('red').style({ cursor: 'pointer' }); //ΠΏΠ΅ΡΠ΅ΠΌΠ΅ΡΠ΅Π½ΠΈΠ΅ ΠΊΠΎΠ½ΡΠ° line1 ΠΏΡΠΈΠΌΠ΅ΡΠ½ΠΎ ΠΏΠΎΠ΄ ΠΊΡΡΡΠΎΡ) function move(event) { line1.attr({ x2: event.pageX, y2: event.pageY }) moveline2() //Π»ΠΎΠ²ΠΈΠΌ ΡΠΎΠ±ΡΡΠΈΠ΅ ΠΏΠ΅ΡΠ΅ΠΌΠ΅ΡΠ΅Π½ΠΈΡ ΠΌΡΡΠΊΠΈ Π½Π° Ρ
ΠΎΠ»ΡΡΠ΅ paper.mousemove(function(event) { line1.attr({ x2: event.pageX, y2: event.pageY }) moveline2() }) paper.mouseup(function() { paper.mousemove(null) }) } //ΡΡΠ½ΠΊΡΠΈΠΎΠ½Π°Π»ΡΠ½Π°Ρ Π·Π°Π²ΠΈΡΠΈΠΌΠΎΡΡΡ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°Ρ Π²ΡΠΎΡΠΎΠΉ Π»ΠΈΠ½ΠΈΠΈ ΠΎΡ ΠΏΠ΅ΡΠ²ΠΎΠΉ (Π»ΡΠ±Π°Ρ) function moveline2() { var x = line1.attr('x2'); var y = line1.attr('y2'); line2.attr({ x2: x / 2, y2: (x + y) / 2 }) } //ΡΡΡΠ°Π½Π²ΠΊΠ° ΡΡΠ½ΠΊΡΠΈΠΈΠ½Π° Π½Π°ΠΆΠ°ΡΠΈΠ΅ ΠΠΠ Π½Π°Π΄ line1 line1.on('mousedown', move) //Π°Π½ΠΈΠΌΠ°ΡΠΈΡ ΠΏΠΎ ΠΊΠ»ΠΈΠΊΡ circle.click(function() { line1.animate().attr({ x2: 300, y2: 400 }) moveline2() }) #draw { width: 400px; height: 400px; border: 2px solid silver } <!DOCTYPE html> <html> <head> <title>ΠΡΠΈΠΌΠ΅Ρ</title> </head> <body> <div id='draw'></div> <script src="https://cdnjs.cloudflare.com/ajax/libs/svg.js/2.4.0/svg.min.js"></script> </body> </html>