2014-07-17 29 views
0

我正在尝试使用Modernizr.prefixed()函数来避免在JS中编写所有供应商代码,但似乎并不奏效。 我想使用它的CSS滤镜,这里是我的代码: Modernizr.prefixed('filter') // returns 'filter' on Chrome which actually needs '-webkit-filter'用Modernizr获取css过滤器的前缀

我已经看了Modernizr的源代码,但它并没有帮助(https://github.com/Modernizr/Modernizr/blob/master/feature-detects/css/filters.js)。

请注意,过滤器的特征检测出现在我的Modernizr版本中。

谢谢!

回答

0

不幸的是,this is really a chromium bug

stucox各地提供了工作,为这个特定的情况下,优秀的年轻绅士,虽然

// This could be written more efficiently, but shows the technique at least 
function getFilterPrefixed() { 
    var elem = document.createElement('div'); 
    var testValue = 'grayscale(1)'; 
    var prop; 
    var i; 

// `Modernizr._prefixes` is a list of known (common) vendor prefixes 
for (i = 0; i < Modernizr._prefixes.length; i++) { 
    prop = Modernizr._prefixes[i] + 'filter'; 

    // Set-and-check: if the property holds a valid value, it's the one 
    elem.style[prop] = testValue; 
    if (elem.style[prop] == testValue) { 
     return prop; 
    } 
    } 
}