Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions tutorials/Mouse Interaction/drag.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<!DOCTYPE html>
<html>
<head>
Expand All @@ -9,6 +10,7 @@

function init() {
stage = new createjs.Stage("demoCanvas");
stage.enableMouseOver(30); // enable mouse over so we can control mouse cursor

// this lets our drag continue to track the mouse even when it leaves the canvas:
// play with commenting this out to see the difference.
Expand All @@ -23,13 +25,20 @@

var dragger = new createjs.Container();
dragger.x = dragger.y = 100;
dragger.cursor = "move";
dragger.addChild(circle, label);
stage.addChild(dragger);


dragger.on("mousedown", function(evt) {
// note where the drag initiated on the shape
evt.currentTarget.dragOffset = evt.currentTarget.globalToLocal(evt.stageX, evt.stageY);
});

dragger.on("pressmove",function(evt) {
// currentTarget will be the container that the event listener was added to:
evt.currentTarget.x = evt.stageX;
evt.currentTarget.y = evt.stageY;
evt.currentTarget.x = evt.stageX - evt.currentTarget.dragOffset.x;
evt.currentTarget.y = evt.stageY - evt.currentTarget.dragOffset.y;
// make sure to redraw the stage to show the change:
stage.update();
});
Expand Down