此Meteor客户端代码无法在公共方法中创建的画布上触发mousemove
事件。 onmousemove
也失败了
可以这样做,如果是这样,怎么办?
Template.report.events({
'click #myElemnt': functionj(event) {
event.target.appendChild(lib.myCanvas());
}
})
//lib.js
lib = (function() {
return {
myCanvas: () => {
let canv = document.createElement('canvas');
//style it here
canv.addEventListener('onmousemove', function() {
console.log('moving');
}
return canv;
}
})();
修改
以下是更改语法
lib = (function() {
return {
myCanvas: () => {
let sigCanvas = document.createElement('canvas');
sigCanvas.style.position = 'absolute';
sigCanvas.style.width = 25 + 'em';
sigCanvas.style.height = 15 + 'em';
sigCanvas.style.top = -90 + 'px';
sigCanvas.style.left = -50 + 'px';
sigCanvas.id = 'signature';
sigCanvas.style.border = '1px solid black';
sigCanvas.addEventListener('onmousemove', function() {
console.log('mouse moving again');
}, false);
return sigCanvas;
}
}());
答案 0 :(得分:0)
根据EventTarget
API,您应该为on
方法提供没有addEventListener
前缀的事件类型。
这应该做的工作:
sigCanvas.addEventListener('mousemove', function(e) {
console.log('mouse moving again');
});