问题描述
什么是保存方式,以检测CSS3 background-size:cover 的支持,特别是在IE< 9?
What is a save way to detect support for CSS3 background-size: cover, especially in IE < 9?
以下测试在IE< 9,因为它实际上将背景大小设置为覆盖:
Following test returns a false positive in IE < 9, because it actually sets background-size to cover:
div.style.backgroundSize = 'cover';
测试时获得的唯一真实结果:
The only true result I get when testing for:
if ('backgroundSize' in div.style)
但根据网站,IE 6/7/8应返回自动,只有覆盖和包含不支持。
But according to the site http://www.standardista.com/css3/css3-background-properties/#bg11, IE 6/7/8 should return auto, only cover and contain are not supported.
编辑:
我想使用自己的解决方案,但我已检查Modernizr使用的。
推荐答案
如果您使用 Modernizr
,您只能下载执行此类任务所需的代码
If you use Modernizr
you can download only the code necessary to perform this kind of task
然后您可以使用
if (Modernizr.backgroundsize) {
/* backgroundSize supported */
}
这篇关于检测对background-size的支持:cover的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!