如何检查CSS calc()是否可用使用JavaScript? [英] How can I check if CSS calc() is available using JavaScript?

查看:759
本文介绍了如何检查CSS calc()是否可用使用JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以检查 CSS函数 calc 可以使用JavaScript吗?



我发现很多关于获得与 calc > 中, /modernizr.com/\"> Modernizr ,您可以在非内核检测中找到 css-calc 的测试。它们使用以下代码:

  Modernizr.addTest('csscalc',function(){
var prop =' width:';
var value ='calc(10px);';
var el = document.createElement('div');

el.style.cssText = prop + Modernizr._prefixes.join(value + prop);

return !! el.style.length;
});


Is there a way to check if the CSS function calc is available using JavaScript?

I found lot of questions and articles about getting the same behaviour as calc using jQuery, but how can I only check if it's available?

解决方案

In Modernizr you can find the test as css-calc currently in the non-core detects. They use the following code:

Modernizr.addTest('csscalc', function() {
    var prop = 'width:';
    var value = 'calc(10px);';
    var el = document.createElement('div');

    el.style.cssText = prop + Modernizr._prefixes.join(value + prop);

    return !!el.style.length;
});

这篇关于如何检查CSS calc()是否可用使用JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆