检测触摸屏设备使用Javascript [英] Detecting touch screen devices with Javascript

查看:154
本文介绍了检测触摸屏设备使用Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Javascript / jQuery的,我怎么能检测如果客户端设备具有鼠标?

In Javascript/jQuery, how can I detect if the client device has a mouse?

我有一个网站,滑了一点信息面板,当用户将鼠标悬停他们的鼠标移到某个项目。我使用jQuery.hoverIntent检测悬停,但这显然并不像iPhone / iPad的/ Android的触摸屏设备的正常工作。因此,在那些设备,我想恢复到挖掘以显示信息面板。

I've got a site that slides up a little info panel when the user hovers their mouse over an item. I'm using jQuery.hoverIntent to detect the hover, but this obviously doesn't work on touchscreen devices like iPhone/iPad/Android. So on those devices I'd like to revert to tap to show the info panel.

推荐答案

+1做悬停点击都。另外一种方法,可以使用CSS媒体查询和使用一些款式只为小屏幕/移动设备,这是最有可能的触摸/自来水功能的人。所以,如果你有通过CSS一些特定的样式,并从jQuery的您检查这些元素为移动设备样式属性,你可以挂接到他们写你的移动特定的code。

+1 for doing hover and click both. One other way could be using CSS media queries and using some styles only for smaller screens / mobile devices, which are the ones most likely to have touch / tap functionality. So if you have some specific styles via CSS, and from jQuery you check those elements for the mobile device style properties you could hook into them to write you mobile specific code.

在这里看到: http://www.forabeautifulweb.com/blog/about/hardboiled_css3_media_queries/

这篇关于检测触摸屏设备使用Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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