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 に答える