zoukankan      html  css  js  c++  java
  • 判断浏览器是否支持css3属性或单位

     1.用CSS.supports()方法 mark-zhq[3]

    //判断是否支持flex布局
    var supportsFlex = CSS.supports("display", "flex");
    
    //判断是否支持rem单位
    var supportsRem = CSS.supports("width","1rem");
    
    //判断兼容性属性
    var supportsAPS = CSS.supports("animation-play-state")||CSS.supports("-webkit-animation-play-state")||CSS.supports("-ms-animation-play-state")||CSS.supports("-Moz-animation-play-state")||CSS.supports("-o-animation-play-state");

    注:这里只针对支持CSS.supports的浏览器,Opera浏览器使用的是不同的方法名。

    判断是否支持该方法:(如果不支持的话可用第三方库Modernizr)

    var supportsCSS = !!((window.CSS && window.CSS.supports) || window.supportsCSS || false);

    2.查找document.documentElement.style是否存在要查询的属性

    function isString(value){
        return typeof value == "string";
    }
    var docStyle = document.documentElement.style;
    var supportsAPS = isString(docStyle.animationPlayState)||isString(docStyle.webkitanimationPlayState)||isString(docStyle.MozanimationPlayState)||isString(docStyle.msanimationPlayState)||isString(docStyle.oanimationPlayState);

    这里不会涉及到实例化,所以可以用typeof去判断数据类型。综合来说第一种方法较好,第二种方法可以帮助理解CSS。

  • 相关阅读:
    Python第二
    Python第一讲以及计算机基础
    MySQL第五讲
    MySQL第四讲
    MySQL第三讲
    MySQL第一讲概论
    MySQL日常笔记第二讲
    Linux修改用户组
    XAMPP中proftpd的简明配置方法
    解决php configure: error: Cannot find ldap libraries in /usr/lib.错误
  • 原文地址:https://www.cnblogs.com/web-easy/p/5291872.html
Copyright © 2011-2022 走看看