【发布时间】:2014-08-17 03:13:44
【问题描述】:
我想点击一些图片上标有笔圈的KineticJS图片:
带有蓝色圆圈的图片工作正常。
带有黄色圆圈的图片每点击 50 次就会起作用。
带有红色圆圈的图片永远无法正常工作。
这就是我添加事件监听器的方式:
蓝色:
var imgLogo = new Image();
imgLogo.src = 'http://folk.ntnu.no/rubenra/web/Resources/bobsByggLogo.png';
imgLogo.onload = function(){
imageLogo = new Kinetic.Image({
image: imgLogo,
x: 10,
y: 580
});
layer.add(imageLogo);
imageLogo.on('mousedown', function() {
console.log('logo trykt');
});
}
黄色:
var imgNextDayButton = new Image();
imgNextDayButton.src = 'http://folk.ntnu.no/rubenra/web/Resources/nextDayButton.png';
imgNextDayButton.onload = function(){
imageNextDayButton = new Kinetic.Image({
image: imgNextDayButton,
x: buttonsBound.getAttr('x')+60,
y: buttonsBound.getAttr('y')+20
});
imageNextDayButton.on('mousedown', function() {
alert('Neste Dag');
console.log('knapp trykt');
});
layer.add(imageNextDayButton);
}
红色:
var imgWarn = new Image();
imgWarn.src = 'http://folk.ntnu.no/rubenra/web/Resources/shapeWarn.png';
imgWarn.onload = function(){
imageWarn = new Kinetic.Image({
image: imgWarn,
x: xstart+100,
y: ystart+45,
width: imgWarn.width,
heigth: imgWarn.height
});
imageWarn.on('mousedown',function(){
alert('Show Warning to ' + name);
})
group.add(imageWarn);
}
这里是sourcecode 的链接。它不适用于 jsbin,但它应该适用于每个代码编辑器。
链接到服务器上的页面: Page on server
【问题讨论】:
标签: javascript mouseevent kineticjs