d3.js双击 [英] d3.js double tap

查看:171
本文介绍了d3.js双击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找关于d3js和移动活动的一些文档?我基本上试图避免双击缩放,然后触发一个单独的函数。目前,我使用此jquery插件来移除在移动设备上的双击/缩放

链接到代码

但是我在任何地方找不到双击d3js的绑定。有一个双击事件将触发双击,但给定当前的jquery插件覆盖缩放我的双击事件不触发。

任何帮助是非常感谢

谢谢! / p>

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!

推荐答案

好的,所以答案是你可以添加一个触摸开始事件。所以这样的东西




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; //不是双击

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

})




请注意,此代码由本 gist 原创并提供由 Wouter Konecny修改

我刚刚将其添加为touchstart事件。按照

})

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

这篇关于d3.js双击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆