問題是關於Element.drag的onstart事件處理程序在新發布的Snap.svg中。Snap.svg - 拖動事件處理程序
下面的代碼的意圖是註冊事件處理程序的svg對象上的拖動(onstart/onstop)的開始和停止。
var s = Snap(800,600);
var bigCircle = s.circle(300,150,100);
bigCircle.drag(null,
function(){
console.log("Move started");
},
function(){
console.log("Move stopped");
}
);
控制檯消息做工精細拖就啓動和停止,但空覆蓋默認onmove功能 - 導致沒有實際阻力發生。我如何傳遞一些說「我不想混淆默認的onmove」的東西?
(注:我寧願通過轉讓的方式來註冊事件處理程序,像大家熟悉的onClick,但那是另一回事)
注意幾個小時後說: 拉斐爾。 js文檔和示例提供了一些線索。至少現在我知道如何在適當的功能,通過對onmove提供默認的移動行爲:
var s = Snap(800,600);
var bigCircle = s.circle(300,150,100);
start = function() {
this.ox = parseInt(this.attr("cx"));
this.oy = parseInt(this.attr("cy"));
console.log("Start move, ox=" + this.ox + ", oy=" + this.oy);
}
move = function(dx, dy) {
this.attr({"cx": this.ox + dx, "cy": this.oy + dy});
}
stop = function() {
this.ox = parseInt(this.attr("cx"));
this.oy = parseInt(this.attr("cy"));
console.log("Stop move, ox=" + this.ox + ", oy=" + this.oy);
}
bigCircle.drag(move, start, stop);
是的,我有同樣的問題,並在這裏結束了,它沒有任何意義,如果我要附着movestart處理程序我有重新定義onmove函數 –