如何使用kineticjs调整线条大小?

时间:2014-04-04 11:29:28

标签: kineticjs

I need to resize the line using kineticjs, I am using kinetic-v5.0.1.js and kinetic-v5.0.1.min.js. Can anyone help me out?
Thanks in Advance,


sample code:

var image = group.find('.' + anchorId + '')[0];
 if (anchorId == "line") {
        var startpoint = group.find('.start')[0];
        var endpoint = group.find('.end')[0];
        var anchorX = activeAnchor.x();
        var anchorY = activeAnchor.y();
        switch (activeAnchor.name()) {

            case 'start':
                console.log("x" + lx + ", y" + ly);
                if (event.pageY < ly && event.pageX > lx) {
                    image.Points([startpoint.x + 1, startpoint.y - 1, endpoint.x, endpoint.y]);
                }
                else if (event.pageY < ly && event.pageX < lx) {
                    image.points([startpoint.x - 1, startpoint.y - 1, endpoint.x, endpoint.y]);
                }
                else if (event.pageY > ly && event.pageX > lx) {
                    image.points([startpoint.x + 1, startpoint.y + 1, endpoint.x, endpoint.y]);
                }
                else {
                    image.points([startpoint.x - 1, startpoint.y + 1, endpoint.x, endpoint.y]);
                }
                //image.setPoints([startpoint.x+1, anchorY, endpoint.x, endpoint.y]);
                ly = event.pageY;
                lx = event.pageX;
                layer.draw();
                break;`enter code here`

            case 'end':
                //image.setPosition(activeAnchor.getPosition());
                image.points([startpoint.x, startpoint.y, anchorX, anchorY]);
                layer.draw();
                break;
        }

图像定义形状,开始和结束是线的锚点,当点击并拖动任何锚线需要调整大小时。此代码可以很好地调整矩形,圆形和文本的大小,使其不适用于行。

1 个答案:

答案 0 :(得分:0)

Kinetic.Line由其points属性控制。

要更改线条,您可以更改其点数:

myLine.points([50,50, 100,100]);

layer.draw();