我有以下代码部分:
Canvas.prototype.pixelOnMouseOver = function pixelOnMouseOver(callback){
var canvas = this._canvas;
var w = this._canvasSize.width, h=this._canvasSize.height;
var data = this._canvas.getImageData(0,0,w,h).data;
canvas.addEventListener('mousemove',function(e){
var idx = (e.offsetY*w + e.offsetX)*4;
var parts = Array.prototype.slice.call(data,idx,idx+4);
callback.apply(canvas,parts);
},false);
和
var wasOver;
antCanvas.pixelOnMouseOver(function(r,g,b,a){
var isOver = a > 10; // arbitrary threshold
if (isOver != wasOver){
wasOver = isOver;
}
});
现在我得到了canvas.addEventListener不是函数的错误。我该如何解决这个问题? Whar是什么原因?
问候
编辑1:这是HTML代码:
<div class="fill pad">
<div style="border:1px solid #ccc" id="aco-canvas"></div>
<input type="file" id="fileInput">
<button id="save_personal_points">Save</button>
<div class="hr vpad"></div>
<div>
<table>
<tr>
<td colspan="2"><b>Debug Info</b></td>
</tr>
<tr style="display:none;" class="aco-info">
<td>Interation: </td><td id="iteration-info"></td>
</tr>
<tr style="display:none;" class="aco-info">
<td>Best Distance: </td><td id="best-distance"></td>
</tr>
<tr style="display:none;" class="position">
<td>Position Info: </td><td id="position"></td>
</tr>
<tr id="aco-buttons">
<td colspan="2"><button id="start-search-btn">Start</button> <button id="clear-graph">Clear</button></td>
</tr>
</table>
我只发布了我认为有趣的部分。因为它只是没有被这么多代码所禁止....