I am using interact in Angular 4.
My draggable function works perfectly.
In my resizable method the event cannot supply me any object property apart from currentTarget and target.
In the example at http://interactjs.io/#resizing:
var target = event.target,
x = (parseFloat(target.getAttribute('data-x')) || 0),
y = (parseFloat(target.getAttribute('data-y')) || 0);
// update the element's style
target.style.width = event.rect.width + 'px';
target.style.height = event.rect.height + 'px';
// translate when resizing from top or left edges
x += event.deltaRect.left;
y += event.deltaRect.top;
event.rect and event.deltaRect cannot be reached. It says that Property event.rect and event.deltaRect are not the type of InteractEvent.
Question Why this is happening?
The whole code is:
let msgFrontX,
msgFrontY,
imgFrontX,
imgFrontY,
msgBackX,
msgBackY,
imgBackX,
imgBackY;
interact('.resize-drag')
.draggable({
// enable inertial throwing
inertia: true,
// keep the element within the area of it's parent
restrict: {
restriction: "parent",
endOnly: true,
elementRect: {
top: 0,
left: 0,
bottom: 1,
right: 1
}
},
// enable autoScroll
autoScroll: true,
onstart: function (event) {},
// call this function on every dragmove event
onmove: dragMoveListener,
// call this function on every dragend event
onend: function (event) {
const parentContainer = event.currentTarget.offsetParent;
const elem = event.currentTarget;
function percentageCalc(direction) {
if (direction === 'horizontal') {
return event.clientX0 / event.clientX 100;
} else {
return event.clientY0 / event.clientY 100;
}
}
if (parentContainer.classList.contains('front')) {
if (elem.classList.contains('msg-container')) {
msgFrontX = percentageCalc('horizontal');
msgFrontY = percentageCalc('vertical');
} else {
imgFrontX = percentageCalc('horizontal');
imgFrontY = percentageCalc('vertical');
}
} else {
if (elem.classList.contains('msg-container')) {
msgBackX = percentageCalc('horizontal');
msgBackY = percentageCalc('vertical');
} else {
imgBackX = percentageCalc('horizontal');
imgBackY = percentageCalc('vertical');
}
}
that.setPositions(msgFrontX, msgFrontY, imgFrontX, imgFrontY,
msgBackX, msgBackY, imgBackX, imgBackY);
}
}).resizable({
edges: {
left: true,
right: true,
bottom: true,
top: true
},
restrict: {
restriction: "parent",
endOnly: true,
elementRect: {
top: 0,
left: 0,
bottom: 1,
right: 1
}
}
}).on('resizeend', function (event) {
console.log(event.resizeRects);
var target = event.target,
x = (parseFloat(target.getAttribute('data-x')) || 0),
y = (parseFloat(target.getAttribute('data-y')) || 0);
// update the element's style
target.style.width = event.rect.width + 'px';
target.style.height = event.rect.height + 'px';
// translate when resizing from top or left edges
x += event.deltaRect.left;
y += event.deltaRect.top;
target.style.webkitTransform = target.style.transform =
'translate(' + x + 'px,' + y + 'px)';
target.setAttribute('data-x', x);
target.setAttribute('data-y', y);
});
function dragMoveListener(event) {
const target = event.target,
// keep the dragged position in the data-x/data-y attributes
x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx,
y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;
// translate the element
target.style.webkitTransform =
target.style.transform =
'translate(' + x + 'px, ' + y + 'px)';
// update the position attributes
target.setAttribute('data-x', x);
target.setAttribute('data-y', y);
}
Error in console
ERROR in C:/Users/usuario/Documents/sitios/tshirtCustom/src/app/customizer/customizer.component.ts (325,34): Property 'rect' does not exist on type 'InteractEvent'.
ERROR in C:/Users/usuario/Documents/sitios/tshirtCustom/src/app/customizer/customizer.component.ts (326,35): Property 'rect' does not exist on type 'InteractEvent'.
ERROR in C:/Users/usuario/Documents/sitios/tshirtCustom/src/app/customizer/customizer.component.ts (329,18): Property 'deltaRect' does not exist on type 'InteractEvent'.
ERROR in C:/Users/usuario/Documents/sitios/tshirtCustom/src/app/customizer/customizer.component.ts (330,18): Property 'deltaRect' does not exist on type 'InteractEvent'.