【发布时间】:2014-08-11 12:04:59
【问题描述】:
我创建了一个带有可滚动背景的 Kineticjs 场景。在这个背景之上是一个带有事件监听器的矩形。我的问题是,在我移动背景并绘制场景后,什么可能导致该事件侦听器不触发。我不知道它可能是什么,我什至打电话给.moveToTop() 看看我是否可以将形状移回顶部,尽管我很确定它仍然是。那么什么会导致事件监听器在平局后停止触发呢?
有人知道解决方法吗?我想我可以将另一个事件侦听器附加到该形状,但如果我做的事情根本上是错误的,这似乎是不必要的。
提前致谢!
编辑:这是一些代码。
// Here is the event listener attached to scroll bar
hscroll4.on('dragmove', updateBackgroundPos4);
// Here is code to move background
var updateBackgroundPos4 = function() {
var hscrollPos = hscroll4.getX();
console.log("mb4: ", mainBody4Dynamic.getX());
mainDynamicWrapper.setX(-hscrollPos+120); //the BG I am moving on scroll
// my attempt at getting it to work
dynamicLayer4.moveToTop();
mainBody4.moveToTop();
mainDynamicWrapper.moveToTop();
newFolder.moveToTop();
dynamicLayer4.draw();
//stage4.drawHit();
};
// Here is the group which contains the rectangle
folderGroup.on('mouseover', function() { //---- this isn't firing after draw
document.body.style.cursor = 'pointer';
console.log("change text");
updateTestText();
});
folderGroup.on('mouseout', function() {
document.body.style.cursor = 'default';
});
编辑 2:即使我的建议也不起作用。重新添加事件侦听器不会使其再次可点击:(
【问题讨论】:
-
你能提供一个小提琴吗?或者至少显示一些代码?
-
我附上了一些代码。我将不得不大量修改代码以创建一个小提琴,所以我希望我附上了足够的内容。
标签: javascript html canvas kineticjs