admin管理员组文章数量:1352863
I'm creating a layout in full css. However, some browser (such as IE6) do not support box-shadow (.. and -webkit-box-shadow or -moz-box-shadow). I would like to check if it's not supported and then add other styles.
How's this possible in jQuery?
Martti Laine
I'm creating a layout in full css. However, some browser (such as IE6) do not support box-shadow (.. and -webkit-box-shadow or -moz-box-shadow). I would like to check if it's not supported and then add other styles.
How's this possible in jQuery?
Martti Laine
Share Improve this question edited Aug 19, 2010 at 17:45 jAndy 236k57 gold badges313 silver badges363 bronze badges asked Aug 19, 2010 at 17:38 Martti LaineMartti Laine 13k22 gold badges70 silver badges103 bronze badges 1- 3 Duplicate? stackoverflow./questions/1342994/… – user113716 Commented Aug 19, 2010 at 17:41
2 Answers
Reset to default 9var check = document.createElement('div');
var shadow = !!(0 + check.style['MozBoxShadow']);
if(shadow)
alert('moz-box-shadow available');
That is the doing-it-yourself way. Other reliable way is the modernizr
library, which does feature detection for you.
http://www.modernizr./
No jQuery needed at all here.
A neat function (pure JavaScript, no jQuery) to check which CSS features are supported by the browser is described in Quick Tip: Detect CSS3 Support in Browsers with JavaScript.
Function is as follows:
var supports = (function() {
var div = document.createElement('div'),
vendors = 'Khtml Ms O Moz Webkit'.split(' '),
len = vendors.length;
return function(prop) {
if (prop in div.style) {
return true;
}
prop = prop.replace(/^[a-z]/, function(val) {
return val.toUpperCase();
});
while (len--) {
if (vendors[len] + prop in div.style) {
// browser supports box-shadow. Do what you need.
// Or use a bang (!) to test if the browser doesn't.
return true;
}
}
return false;
};
})();
Usage is like this:
if (supports('boxShadow')) {
// Do whatever
}
It worked like a charm for me! :-)
本文标签: javascriptHow to check if css boxshadow is supported (jQuery)Stack Overflow
版权声明:本文标题:javascript - How to check if css box-shadow is supported (jQuery)? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743919385a2561806.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论