jQuery中的Longpress / longclick事件支持/插件 [英] Longpress / longclick event support / plugin in jQuery

查看:169
本文介绍了jQuery中的Longpress / longclick事件支持/插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个需要鼠标悬停菜单的网站。我不建议从可访问性的角度来看鼠标悬停菜单,但是使用jQuery很容易实现。

I'm working on a website which requires mouseover menu's. I would not recommend mouseover menu's from an accessibility point of view, but it's pretty easy to implement using jQuery.

问题:我们还需要支持触摸屏设备(平板电脑) 。在这样的设备上,您没有鼠标,因此鼠标悬停事件不起作用。我希望jQuery有一个longpress事件,但事实并非如此。我确实找到了使用Google的 jQuery longclick插件,但这是针对jQuery 1.4的,所以我并不热衷于使用它。此外,jQuery插件网站目前正处于维护状态,因此不是很有帮助。

The problem: we also need to support touchscreen devices (tablets). On such a device you don't have a mouse and, so the mouseover event is not working. I was hoping for jQuery to have a longpress event, but it doesn't. I did find a jQuery longclick plugin using Google, but it was for jQuery 1.4, so I'm not keen on using that. Also the jQuery plugin site is under maintenance at the moment, so that is not very helpful.

所以问题是:是否有一个优雅的jQuery 1.7 / 1.8插件支持longpress / longclick事件?

So the question: is there an elegant plugin for jQuery 1.7 / 1.8 to support longpress / longclick events?

推荐答案

事实证明你可以使用现有的 longclick插件

It turns out that you can just use the existing longclick plugin for jQuery 1.4 with jQuery 1.8.

$("#area").mousedown(function(){
    $("#result").html("Waiting for it...");
});
$("#area").longclick(500, function(){
    $("#result").html("You longclicked. Nice!");
});
$("#area").click(function(){
    $("#result").html("You clicked. Bummer.");
});

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="http://rawgit.com/pisi/Longclick/master/jquery.longclick-min.js"></script>
    
<p id="area">Click me!</p>
<p id="result">You didn't click yet.</p>

这篇关于jQuery中的Longpress / longclick事件支持/插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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