Skip to content

Instantly share code, notes, and snippets.

@piouc
Created August 24, 2023 06:31
Show Gist options
  • Save piouc/329c495659fcea28fcee8f1758192021 to your computer and use it in GitHub Desktop.
Save piouc/329c495659fcea28fcee8f1758192021 to your computer and use it in GitHub Desktop.
getPosision.js
let point = null
window.addEventListener('mousedown', e => {
if(point){
console.log(`x="${point.x / window.innerWidth * 100}vw" y="${point.y / window.innerWidth * 100}vw" width="${(e.clientX + window.scrollX - point.x) / window.innerWidth * 100}vw" height="${(e.clientY + window.scrollY - point.y) / window.innerWidth * 100}vw"`)
point = null
} else {
point = {
x: e.clientX + window.scrollX,
y: e.clientY + window.scrollY
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment