+ 5

Svg take coordinates of a <rect> in js

I've : <svg class='bloc-1'> <rect.../> </svg> <svg class='bloc-2'> <rect.../> </svg> they are draggable. how to take the coordinates of bloc-1 and bloc-2 ? (x1,y1 = bloc-1 and x2,y2 = bloc-2) I want to know : if (x1==x2 && y2-y1 == 100) { } I've positionned the 2 svg not correctly and the user need to align them correctly to finish the level. and it's why I want to have the coordonates, with the if (){} which listen to if the block are aligned

30th Sep 2017, 6:40 PM
NoxFly
NoxFly - avatar
1 Respuesta
+ 2
rect = document.getElementById("rect"); var pts = rect.getBoundingClientRect(); console.log(pts.left); console.log(pts.top); https://code.sololearn.com/WM4VmVB8twIN/?ref=app
1st Oct 2017, 1:11 AM
Calviղ
Calviղ - avatar