问题描述
我最近开始使用fabricjs,并且对连接对象有疑问.我确实为从parent object
到child object
的连接创建示例演示,并用箭头连接.我得到了示例演示http://kpomservices.com/HTML5CanvasCampaign/campaign.html
.此代码应与结构1.4.2.一起使用.对于版本2.3.3无效的代码,可能有类似的代码.
I recently started to work with fabricjs, and I have a question about connectivity object. i do creating sample demo for connectivity from parent object
to child object
connect with arrow. I got sample demo http://kpomservices.com/HTML5CanvasCampaign/campaign.html
. This code should work with fabric 1.4.2.A similar code is possible for the version 2.3.3 not work.
错误functions.js:963 Uncaught TypeError: c.setAngle is not a function
代码
function makeArrow(centerpt, left, top, line) {
var c = new fabric.Triangle({
width: 10,
height: 10,
left: left,
top: top,
//selectable: false,
strokeWidth: 3,
fill: 'grey',
opacity: 1,
stroke: 'grey',
originX: 'center',
originY: 'center'
});
c.hasBorders = c.hasControls = false;
c.angle = 90;
c.line = line;
var dx = left - centerpt.x;
var dy = top - centerpt.y;
var angle = Math.atan2(dy, dx) * 180 / Math.PI;
c.setAngle(angle + 90);
c.setCoords();
c.name = 'ep';
line.ep = c;
c.line = line;
return c;
}
推荐答案
内部版本没有setter/getter(可选).您可以使用Named accessors
在此处进行构建.如果要设置角度,可以使用
Build doesn't have setter/getter (optional). You can make your build here with Named accessors
. If you want to set angle you can use
obj.angle = text;
//or
obj.set({
angle:angle
});
//or
obj.set('angle', angle);
演示
DEMO
var canvas = new fabric.Canvas('c');
var triangle = new fabric.Triangle({
left: 150,
top: 50,
width: 300,
height:200,
fill:'',
stroke:'red'
})
canvas.add(triangle);
triangle.set('angle',40);
//triangle.angle = 40;
//triangle.set({angle : 40})
canvas{
border:1px solid #000;
}
<script type="text/javascript" src="
https://rawgit.com/kangax/fabric.js/master/dist/fabric.js"></script>
<canvas id="c" width="400" height="400"></canvas>
这篇关于setAngle不是fabricjs函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!