【发布时间】:2014-03-18 05:56:24
【问题描述】:
使用 phonejs 制作移动应用程序,我正在使用带有强制布局的 d3.js。我想在 d3 的节点被双击或按住时添加一些功能。 但是双击事件在手机中没有任何作用。我也尝试了 jQuery 触摸事件,但在这里不起作用。 如何在 d3 的节点上放置触摸事件?
这里是节点:
node = container.append("g").selectAll("image.node")
.data(nodes_edges_json.nodes)
.enter().appent("g").append("svg:image")
.attr("class", "node")
.attr("xlink:href", function(nodeObj) { return setImage(nodeObj); })
.attr("width", function(nodeObj) { return setHeightWidth(nodeObj); })
.attr("height", function(nodeObj) { return setHeightWidth(nodeObj); })
.on("dblclick", function(data, index) {
d3.event.preventDefault();
getdata(data, index);
});
【问题讨论】:
-
This question 应该会有所帮助。
-
我试过了但没用..@Lars Kotthoff
-
你试过用
touchstart吗? -
touchstart 事件被识别,但我想在节点上点击或双击事件..@MacroCI
-
我认为你必须使用另一个库来支持它,因为你需要计时器。对于双击,请查看其他答案:stackoverflow.com/questions/13479236/d3-js-double-tap,而对于按住此选项也可能有用:stackoverflow.com/questions/2625210/long-press-in-javascript 更多,请查看此要点:bl.ocks.org/eweitnauer/7144421