只需为dragend添加另一个处理程序,如下所示:scroller.on('dragend', function(event){ layer.moveToTop(); layer.draw();});这是更新的小提琴.有关所面临问题的更多详细信息/说明,请检查以下内容: https://github.com. com/ericdrowell/KineticJS/issues/219 I have a scrollbar that moves a layer, so the layer is moved while in the scrollbar's "dragmove" callback. This causes all bound events to be disconnected on the moved layer!Please see this fiddle: http://jsfiddle.net/NY4QK/10/var stage = new Kinetic.Stage({ container: 'container', width: 200, height: 200,});var fixedLayer = new Kinetic.Layer();stage.add(fixedLayer);var old_x = 100;var old_y = 100;var scroller = new Kinetic.Circle({ x: old_x, y: old_y, radius: 10, fill: '#00F', stroke: 'black', strokeWidth: 4, draggable: true});scroller.on('dragmove', function(event){ var pos = scroller.getAbsolutePosition(); layer.move(pos.x - old_x, pos.y - old_y); old_x = pos.x; old_y = pos.y; layer.draw();});fixedLayer.add(scroller);var layer = new Kinetic.Layer();stage.add(layer);var rect = new Kinetic.Rect({ x: 10, y: 10, width: 50, height: 50, fill: '#0F0', stroke: 'black', strokeWidth: 4});rect.on('click', function(){ rect.remove(); layer.draw();});layer.add(rect);layer.draw();fixedLayer.draw();Is this a bug or am I doing something wrong? 解决方案 When you use a drag event, KineticJS create a temporary layer on top as a result of which your events where not getting registered after the dragmove.Just add another handler for dragend like this:scroller.on('dragend', function(event){ layer.moveToTop(); layer.draw();});And here is the updated fiddle.For more details/explanation on the problem you faced, check this: https://github.com/ericdrowell/KineticJS/issues/219 这篇关于从“拖动"图标中移动图层后,事件丢失.打回来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 19:17