问题
I'm looking for some documentation on d3js and mobile events? I'm basically trying to avoid double tap zoom and then trigger a separate function. Currently I'm using this jquery plugin to remove double tap/zoom on mobile
link to the code
But I can't find anywhere a binding of double tap in d3js. There is a double click event that will fire on double tap but given the current jquery plugin to override zoom my double click event does not fire.
Any help is much appreciated
Thanks!
回答1:
Ok so the answer is you can add a touch start event. So something like this
g.append("rect").on("touchstart",function(){
var t2 = e.timeStamp,
t1 = $(this).data('lastTouch') || t2,
dt = t2 - t1,
fingers = e.originalEvent.touches.length;
$(this).data('lastTouch', t2);
if (!dt || dt > 500 || fingers > 1) return; // not double-tap
e.preventDefault(); // double tap - prevent the zoom
})
Please note that this code is provided originaly by this gist and was modified by Wouter Konecny
I just added it as a touchstart event. Works like a charm by the way
来源:https://stackoverflow.com/questions/13479236/d3-js-double-tap