2011-12-14 102 views
0

我發現html5canvastutorials.com這個教程:html5工具提示對象?

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對象?或者我在這裏錯過了什麼?

+2

看 - 他們定義工具提示爲Kinetic.Shape在這個例子:http://www.html5canvastutorials.com/labs/html5 -canvas-隨機圈與 - 工具提示/ – kinakuta 2011-12-14 18:24:30

回答

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 
      });