html5工具提示对象?

时间:2011-12-14 18:19:32

标签: html5 canvas tooltip html5-canvas kineticjs

我在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对象?或者我在这里错过了什么?

1 个答案:

答案 0 :(得分: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
            });