Created
January 11, 2018 01:02
-
-
Save pathunstrom/574878278f7ae9d3cdab349b33920423 to your computer and use it in GitHub Desktop.
Dual Movement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
<style> | |
.box { | |
height: 100px; | |
width: 100px; | |
top: 100px; | |
} | |
#blue { | |
background-color: blue; | |
position: absolute; | |
left: 100px; | |
} | |
#red { | |
background-color: red; | |
position: absolute; | |
left: 500px; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="blue" class="box"></div> | |
<div id="red" class="box"></div> | |
<script> | |
let box_mover = { | |
focus_box: undefined, | |
mouse_position: [0, 0], | |
mouse_offset: [0, 0], | |
moving: false, | |
set_box: (event) => { | |
this.mouse_position = [event.clientX, event.clientY] | |
this.mouse_offset = [event.offsetX, event.offsetY] | |
this.moving = true | |
}, | |
animate: () => { | |
if (this.moving) { | |
} | |
}, | |
move_position: (event) => { | |
} | |
} | |
let boxes = document.getElementsByClassName("box") | |
let red = document.getElementById("red") | |
let blue = document.getElementById("blue") | |
console.log(red) | |
console.log(blue) | |
for (let i=0;i<boxes.length;i++) { | |
let box = boxes.item(i) | |
box.addEventListener("click", (event) => {console.log(event); console.log(box.id + " clicked!")}) | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment