-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
64 lines (51 loc) · 1.32 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var canvas = new fabric.Canvas('canvas');
var pos = {x:0,y:0}
var box = new fabric.Rect({
fill: '',
stroke: 'gray',
strokeWidth:1,
height: 100,
width: 100,
top: -50,
left: -50,
originX: 'center',
originY: 'center'
})
var arrowBottom = new fabric.Path('M 0 0 L -8 8 M 0 0 L 8 8 z', {
left: -50,
top: -50,
stroke: 'red',
strokeWidth: 3,
fill: false,
originX: 'center',
originY: 'center'
});
var arrowTop = new fabric.Path('M 0 0 L -4 -4 M 0 0 L -4 4 z', {
left: 0,
top: -100,
stroke: 'green',
strokeWidth: 1,
fill: false,
originX: 'center',
originY: 'center'
});
var shape = new fabric.Group([box, arrowTop, arrowBottom],{
top: 200, left:200
})
canvas.add(shape);
// canvas.on('mouse:move', (event)=>{
// xy = canvas.getPointer(event.e)
// console.log(xy.x, xy.y)
// })
var moveHandler = function (evt) {
var movingObject = evt.target;
console.log('moved:',movingObject.get('left'), movingObject.get('top'));
};
var modifiedHandler = function (evt) {
var modifiedObject = evt.target;
console.log('modified: ', modifiedObject.get('left'), modifiedObject.get('top'));
};
canvas.on({
'object:modified': modifiedHandler,
'object:moving': moveHandler
})