2014-07-17 28 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; 
    } 
    } 
}