我想测试浏览器是否支持特定的 css 属性。对于 css 属性,我可以这样做
document.createElement("detect").style["-webkit-overflow-scrolling"] === ""
但是如果我必须检查特定的类或属性怎么办。例如,我想测试对
的支持position:fixed
我该怎么做(除了使用 Modernizr)?请帮忙。
最佳答案
function isFixedSupported() {
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;
}
var canUseFixed = isFixedSupported(); //true:false
关于javascript - 检查对 css property 属性的支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10211300/