我正在尝试direction
动态设置,但有些东西不起作用。我没有收到错误。
function moveSelection(keyPressed) {
var group = canvas.getActiveGroup(),
obj = canvas.getActiveObject();
if(!group && !obj) {return;}
var direction = '',
sign = '',
operators = {
'+': function(a, b) { return a + b },
'-': function(a, b) { return a - b },
};
switch(keyPressed) {
case 37:
direction = 'left';
sign = '-';
break;
case 38:
direction = 'top';
sign = '-';
break;
case 39:
direction = 'right';
sign = '+';
break;
case 40:
direction = 'bottom';
sign = '+';
break;
}
if(group){
group.set({
direction : operators[sign](group.get(direction), 1)
});
canvas.renderAll();
} else {
obj.set({
direction : operators[sign]( obj.get(direction),1 )
});
canvas.renderAll();
}
}
但是当我将代码更改为以下代码时,它工作正常.. 有什么问题?谢谢:
obj.set({
'left' : operators[sign]( obj.get(direction),1 )
});