Get relative position between 2 DOM elements using JavaScript

前端 未结 3 644
天命终不由人
天命终不由人 2020-12-09 05:00

I\'ve implemented a set of draggable elements that can be dropped into some containers using jQuery. What I need is an animation that moves an element to a specific containe

3条回答
  •  我在风中等你
    2020-12-09 05:34

    Using pure javascript.

    var dx = obj1.offsetLeft - obj2.offsetLeft;
    var dy = obj1.offsetTop - obj2.offsetTop;
    var distance = Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2));
    

提交回复
热议问题