// get the bounding rectangles
var div1rect = $("#div1")[0].getBoundingClientRect();
var div2rect = $("#div2")[0].getBoundingClientRect();
// get div1's center point
var div1x = div1rect.left + div1rect.width/2;
var div1y = div1rect.top + div1rect.height/2;
// get div2's center point
var div2x = div2rect.left + div2rect.width/2;
var div2y = div2rect.top + div2rect.height/2;
// calculate the distance using the Pythagorean Theorem (a^2 + b^2 = c^2)
var distanceSquared = Math.pow(div1x - div2x, 2) + Math.pow(div1y - div2y, 2);
var distance = Math.sqrt(distanceSquared);
Code Example |
---|
:: |
:: send back text from get request in node.js |
Javascript :: |
:: |
Javascript :: |
:: |
:: |
:: redux counter |
:: use ES6 import syntax when you enhance the script tag |
Javascript :: |
:: |
Javascript :: array.includes is not a function react |
Javascript :: md5 online decrypt |
:: dynamically define routes separated in different pages for React |
:: how to change in website with node js |
:: como gerar numeros aleatorios em javascript a partir de uma função |
Javascript :: |
Javascript :: decrypt javascript code |
Javascript :: js to ts converter |
:: create a friend component react js |
:: what is renderer in three.js |
Javascript :: Tow sums |
:: react using props and parent state |
:: |
:: formart japanese date in js |
Javascript :: |
:: say something in console javascript |
:: |
Javascript :: onclick add and remove class using jquery |
Javascript :: |