0

我正在尝试使用 KineticJS 在图像上绘制不同的形状,并使用不同的按钮进行放大和缩小,每个元素都可以通过 itsetlf 正常工作,但是当我在同一页面上组合所有功能时,没有任何效果。这是绘制线条的脚本:

 if (drawnewline) {
            document.getElementById('dLine').onclick = function() {
                    layer.on("mousedown", function () {
                        if (moving) {
                            moving = false;
                            layer.draw();
                        } else {
                            var mousePos = stage.getMousePosition();
                            x1 = mousePos.x;
                            y1 = mousePos.y;
                            line = new Kinetic.Line({
                                points: [0, 0, 50, 50],
                                stroke: "red"
                            });
                            layer.add(line);
                            line.getPoints()[0].x = mousePos.x;
                            line.getPoints()[0].y = mousePos.y;
                            line.getPoints()[1].x = mousePos.x;
                            line.getPoints()[1].y = mousePos.y;
                            moving = true;
                            layer.drawScene();
                        }
                    });

                    layer.on("mousemove", function () {
                        if (moving) {
                            var mousePos = stage.getMousePosition();
                            var x = mousePos.x;
                            var y = mousePos.y;
                            line.getPoints()[1].x = mousePos.x;
                            line.getPoints()[1].y = mousePos.y;
                            moving = true;
                            layer.drawScene();
                        }
                    });

                    layer.on("mouseup", function () {
                        moving = false;
                        var mousePos = stage.getMousePosition();
                        x2 = mousePos.x;
                        y2 = mousePos.y;
                        $("#distance").val(calculateDistance(x1, y1, x2, y2));

                    });
                };
            };

完整的脚本可以在http://jsfiddle.net/MEQxq/查看。我会很感激你的建议,并在此先感谢。

4

1 回答 1

0

我通过在 getElementById 中移动“if (drawnewline)”解决了这个问题!还要删除鼠标操作,例如 layer.off('mousemove');。

于 2013-03-25T20:15:19.007 回答