Created
November 15, 2013 20:12
-
-
Save kkga/7490828 to your computer and use it in GitHub Desktop.
move
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
// 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