Home > Web Front-end > HTML Tutorial > 判断浏览器是否支持css3属性或单位_html/css_WEB-ITnose

判断浏览器是否支持css3属性或单位_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:22:11
Original
1698 people have browsed it

 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");
Copy after login

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

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

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

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);
Copy after login

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

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template