本文介绍了Webkit等效于:-moz-system-metric(touch-enabled)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来像一个真正有用的CSS选择器,在移动网站上工作。

:-moz-system-metric(touch-enabled) looks like a really useful CSS selector for working on mobile sites.

不幸的是,Webkit在移动触摸设备上占据主导地位,因此任何人都知道是否有Webkit等效项?

Unfortunately Webkit is dominant on mobile touch devices so does anyone know if there is a Webkit equivalent?

理想情况下,这将是好的,如果这是由CSS3媒体查询管理)

(Ideally it'd be good if this was managed by CSS3 media queries)

编辑:

推荐答案

目前没有办法使用Javascript,无法实现这一点。

There's no way to accomplish this without resorting to Javascript, at present.

像@easwee说,是一个着名的JS库,专注于特征检测。您可以使用 touch 测试您的用例。

As @easwee said, Modernizr is a well-regarded JS library that focuses on feature detection. You can use its touch test for your use case.

如果您不需要Modernizr的所有铃声,可以执行以下操作:

If you don't need all of Modernizr's bells and whistles, you can do the following:

A)在< body> 标记:

<script type="text/javascript">
if( !!window.TouchEvent ) body.className += " touch-enabled ";
</script>

B)编写CSS。由于Gecko使用媒体查询来通知您触摸可用性,因此您必须复制触摸特定CSS,例如:

B) Write your CSS. Since Gecko uses a media query to inform you of touch availability, you'll have to dupe the touch-specific CSS, like so:

BODY.touch-enabled DIV.foo
{
    /* touch-specific CSS */
}

@media screen and (-moz-touch-enabled)
{
DIV.foo
{
    /* touch-specific CSS */
}

}

如果每个选择器代码在两种情况下都是相同的,GZIP应该优化掉一些重复。 (您使用压缩,我希望。)

If the per-selector code is identical in both circumstances, GZIP ought to optimize away some of the duplication. (You are using compression, I hope.)

这篇关于Webkit等效于:-moz-system-metric(touch-enabled)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 13:44