0

我在 html5canvastutorials.com 上找到了本教程:

var triangle = new Kinetic.Shape(function(){
                var context = this.getContext();
                context.beginPath();
                context.lineWidth = 4;
                context.strokeStyle = "black";
                context.fillStyle = "#00D2FF";
                context.moveTo(120, 50);
                context.lineTo(250, 80);
                context.lineTo(150, 170);
                context.closePath();
                context.fill();
                context.stroke();
            });

            triangle.addEventListener("mousemove", function(){
                var mousePos = stage.getMousePos();
                tooltip.x = mousePos.x;
                tooltip.y = mousePos.y;
                tooltip.text = "Cyan Triangle";
                tooltip.draw();
            });

tooltip对象在没有预先定义的情况下被使用。HTML 5 画布是否有预定义的tooltip对象?或者我在这里错过了什么?

4

1 回答 1

1

您错过了这部分代码:

var tooltip = new Kinetic.Shape(function(){
                var context = this.getContext();
                context.beginPath();
                context.fillStyle = "black";
                context.fillRect(5, 5, 200, 30);
                context.font = "12pt Calibri";
                context.fillStyle = "white";
                context.textBaseline = "top";
                context.fillText(tooltip.text, 10, 10);
            }, {
                x: 5,
                y: 5,
                width: 200,
                height: 30
            });
于 2011-12-14T18:38:25.603 回答