【问题标题】:Detect id of div with hammer.js / by touch用hammer.js/通过触摸检测div的id
【发布时间】:2013-02-12 17:42:30
【问题描述】:

我有一个带有 ID 的图像网格。当用户在移动触摸设备上捏捏时,我想检测用户捏捏的是哪个实例。因此,我不想为每个尝试检测夹点的 ID 创建 30 个锤子实例,而是想反过来​​检测它。我希望我的问题很清楚。

干杯!

【问题讨论】:

  • 你也用jQuery吗?

标签: jquery touch hammer.js


【解决方案1】:

您可以使用event-object 来确定当前的target

$(document).on('touchstart', function(e){
    $(e.target) // this is your element
});

或者如果您需要在touchmove 上进行测试,请使用elementFromPoint 和手指坐标:

$(document).on('touchmove', function(e){
    $( document.elementFromPoint(e.touches[0].pageX, e.touches[0].pageY) ) // this is your element
});

更新

您可以使用$.event.props.push("touches"); 来规范化touches

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-05
    • 1970-01-01
    • 2013-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多