我正在寻找任何像modernizr(实际上没有)为“旧浏览器”(polyfill)启用flexbox的javascript库。
是的,我知道这是一个非常新的功能(事实上“没有”是一个有效的答案),但我希望有这样的东西,我总是很难水平+垂直居中,这真的会有所帮助并缩短工作。
我的意思是这个 flexbox:http ://weblog.bocoup.com/dive-into-flexbox/ (最新的)
你将不得不创建自己的。 http://www.sitepoint.com/detect-css3-property-browser-support/有一个标题为“滚动你自己的检测代码”的部分
基本上你需要这样的东西:
// detect CSS display:flex support in JavaScript
var detector = document.createElement("detect");
detector.style.display = "flex";
if (detector.style.display === "flex") {
console.log("Flex is supported");
}
else
{
console.log("Flex is not supported");
}
要对此进行扩展并创建一个函数:
function DetectDisplayValue(val)
{
// detect CSS display:val support in JavaScript
//
var detector = document.createElement("detect");
detector.style.display = val;
if (detector.style.display === val) {
console.log("Display value: " + val + " is supported");
}
else
{
console.log("Display value: " + val + " is not supported");
}
}