Fiddle - jsfiddle
sequencing:
- draw the line at coordinates (x1 = 50, y1 = 50, x2 = 450, y2 = 50)
- Checking coordinate y1. y1 = 50
- Move the line on the y-axis by 50 pixels.
- Checking coordinate y1. LEFT y1 = 50 ??? Why is that? And how to get the true coordinates?
var canvas = new fabric.Canvas('c');
var line = new fabric.Line([50, 50, 450, 50], {
stroke: 'blue',
strokeWidth : 10,
hasControls: false,
hasBorders: false,
lockMovementX: true,
lockMovementY: true,
hoverCursor: 'default'
});
canvas.add(line);
document.querySelector('#getLineY').onclick=function(e) {
alert(line.get('y1'));
}
document.querySelector('#movedown').onclick=function(e) {
line.top=line.top+50;
canvas.renderAll();
}
canvas {
border: solid 1px black;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.1.0/fabric.all.min.js"></script>
<button id="getLineY">getLineY</button>
<button id="movedown">movedown</button>
<canvas id="c" width="500" height="500" ></canvas>