$(function() { init(); }); // mouse interaction drag // 拖动物体的时候,防止鼠标按下的时候对象突然跳动一下; var stage, output; var diff={}; // 偏移量; function init(e) { stage = new createjs.Stage(‘demo1‘); stage.mouseMoveOutside = true; var circle = new createjs.Shape(); circle.graphics.beginFill(‘red‘).drawCircle(0,0,50); var label = new createjs.Text(‘drag me‘,‘bold 14px Arial‘,‘#ffffff‘); label.textAlign = ‘center‘; label.y = -7; var dragger = new createjs.Container(); dragger.x = dragger.y = 100; dragger.addChild(circle, label); stage.addChild(dragger); dragger.on(‘pressmove‘,function(evt){ evt.currentTarget.x = evt.stageX-diff.x; evt.currentTarget.y = evt.stageY-diff.y; stage.update(); }); dragger.on(‘mousedown‘,function(evt){ // plan1 // diff = dragger.globalToLocal( evt.stageX,evt.stageY); // console.log(diff); // plan2 diff.x = evt.stageX-evt.currentTarget.x; diff.y = evt.stageY-evt.currentTarget.y; console.log(diff); }); stage.update(); }
时间: 2024-10-09 00:37:45