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

查看:31
本文介绍了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.

问题:我们还需要支持触摸屏设备(平板电脑).在这样的设备上,您没有鼠标,因此 mouseover 事件不起作用.我希望 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?

推荐答案

原来你可以只使用现有的用于 jQuery 1.4 和 jQuery 1.8 的 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天全站免登陆