Skip to content

Instantly share code, notes, and snippets.

@stevekm
Forked from pathunstrom/index.html
Created January 11, 2018 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevekm/cf90c591e6d51a1827ad3915b19f972a to your computer and use it in GitHub Desktop.
Save stevekm/cf90c591e6d51a1827ad3915b19f972a to your computer and use it in GitHub Desktop.
Dual Movement
<!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