How to detect lack of position:fixed in a generic way?

点点圈 提交于 2019-11-30 22:14:18

Run the following function to test for position:fixed support.

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;
}

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

also returns a false-positive on Opera Mini.

Why not simply set a position:fixed on some element and then read it back? If position:fixed not supported returned value, should not be equal to fixed in theory

that does not work on Opera Mini: you can set position to "fixed", it will read as "fixed" even though it is not supported.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!