如何检测缺乏位置:以通用方式固定? [英] How to detect lack of position:fixed in a generic way?

查看:138
本文介绍了如何检测缺乏位置:以通用方式固定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在移动设备(如iPad)上,我想禁用只有在支持position:fixed时才能使用的功能。有没有办法检测这些设备,而不使用用户代理字符串?原因是,如果可能,我想避免搜索iPad,iPhone,iPod,Android等。

On mobile devices such as the iPad, I would like to disable a feature that only works if position:fixed is supported. Is there a way to detect these devices without using the user agent string? The reason is that I would like to avoid searching for iPad, iPhone, iPod, Android, etc if possible.

推荐答案

以下函数来测试 position:fixed 支持。

function () {
  var isSupported = null;
  if (document.createElement) {
      var el = document.createElement("div");
      if (el && el.style) {
          el.style.position = "fixed";
          el.style.top = "10px";
          var root = document.body;
          if (root && root.appendChild && root.removeChild) {
              root.appendChild(el);
              isSupported = el.offsetTop === 10;
              root.removeChild(el);
          }
      }
  }
  return isSupported;
}

http://kangax.github.com/cft/#IS_POSITION_FIXED_SUPPORTED

这篇关于如何检测缺乏位置:以通用方式固定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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