Skip to content

Instantly share code, notes, and snippets.

@kkga
Created November 15, 2013 20:12
Show Gist options
  • Save kkga/7490828 to your computer and use it in GitHub Desktop.
Save kkga/7490828 to your computer and use it in GitHub Desktop.
move
// a simple fucking view with random color
view = new View ({
x:200,
y:200,
width:300,
height:300,
})
view.style.backgroundColor = utils.randomColor(0.5)
// which we want to move around smoothly
function moveX(event) {
if (event.x < view.midX) {
view.animate({
properties: {
x : event.x + view.midX
}
})
} else if (event.x > view.midX) {
view.animate({
properties: {
x : event.x - view.midX
}
})
}
}
function moveY(event){
if (event.y < view.midY) {
view.animate({
properties: {
y : event.y + view.midY
}
})
} else if (event.y > view.midY) {
view.animate({
properties: {
y : event.y - view.midY
}
})
}
}
// okay, let's move this thing, finally
view.on("mouseover", function(event) {
document.addEventListener("mousemove", moveX)
})
view.on("mouseover", function(event) {
document.addEventListener("mousemove", moveY)
})
view.on("mouseout", function(event) {
document.removeEventListener("mousemove")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment