我正在嘗試創建一個可拖動的圓。爲什麼在d3.behavior.drag()中定義了isnt`d`
var drag = d3.behavior.drag();
drag.on("drag", function(d,i) {
console.log(d);
d.x += d3.event.dx;
d.y += d3.event.dy;
//This will change the center coordinates by the delta
d3.select(this).attr("x", d.x).attr("y", d.y);
//This should change the upper left x and y values by the delta
d3.select(this).attr("transform", function(d,i){
return "translate(" + [ x,y ] + ")"
})
})
這裏是fiddle
它拋出錯誤在右邊紅圈的一舉一動,但怎麼就被說d
在線路3,4不定,所以5?
任何想法,爲什麼這是?所有的例子似乎都有'd'作爲處理程序的第一個參數。 –
不在文檔中:https://github.com/mbostock/d3/wiki/Drag-Behavior「」drag「:當元素被拖動時觸發.d3.event將包含」x「和」y「屬性,分別代表當前絕對拖動座標...「 –
@ Joe:是的。這些文檔對於調用回調的含義非常模糊。我想知道爲什麼我能找到的所有例子都接受一個論點,它*具有*作爲早期版本或其他東西。 (這是我的+1順便說一句) –