Longpress / longclick event support / plugin in jQuery(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 事件支持/插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:jQuery 中的 Longpress/longclick 事件支持/插件
基础教程推荐
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
