对可以拖动的元素应用撤消重做(拖放) [英] Apply Undo Redo on elements that can dragable (drag and drop)
本文介绍了对可以拖动的元素应用撤消重做(拖放)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在svgElements上实现可以用javascript拖动的功能我怎么能这样做...
I want to implement functionality on the svgElements that can be dragged with javascript how could I do this...
我用鼠标实现了这个
当鼠标出现时,我保存x和y位置,对象ID,对象类型(圆形,矩形等)
When mouse up occurs, I save the x and y position, object id, object type (circle, rect, etc.)
任何人都能告诉......这是实施的好方法吗?
推荐答案
我在示例中看到一个小问题,有时候你会忘记这一点。
I see a little issue in the example, you forget sometimes this.
var history = {
stack : [],
counter : -1,
add : function(item){
this.stack[++this.counter] = item;
this.doSomethingWith(item);
// delete anything forward of the counter
this.stack.splice(this.counter+1);
},
undo : function(){
this.doSomethingWith(this.stack[--this.counter]);
},
redo : function(){
this.doSomethingWith(this.stack[++this.counter]);
},
doSomethingWith : function(item){
// show item
}
};
这篇关于对可以拖动的元素应用撤消重做(拖放)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文