2016-07-13 1 views
-2

Ich versuche, einen Filter auf ein Bild basierend auf Browser-Unterstützung anzuzeigen.wie überprüft man, ob der Browser eine bestimmte CSS-Eigenschaft unterstützt

Wie überprüfe ich, ob der Browser eine bestimmte CSS-Eigenschaft wie Filter und --webkit-Filter mit Javascript unterstützt?

Ich verwende die folgende Funktion, aber seine Arbeit nicht

isCSSStyleSupported: function(prop, value) { 
      // If no value is supplied, use "inherit" 
      value = arguments.length === 2 ? value : 'inherit'; 
      // Try the native standard method first 
      if ('CSS' in window && 'supports' in window.CSS) { 
       return window.CSS.supports(prop, value); 
      } 
      // Check Opera's native method 
      if('supportsCSS' in window){ 
       return window.supportsCSS(prop, value); 
      } 
      // Convert to camel-case for DOM interactions 
      var camel = prop.replace(/-([a-z]|[0-9])/ig, function(all, letter) { 
       return (letter + '').toUpperCase(); 
      }); 
      // Check if the property is supported 
      var support = (camel in el.style); 
      // Create test element 
      var el = document.createElement('div'); 
      // Assign the property and value to invoke 
      // the CSS interpreter 
      el.style.cssText = prop + ':' + value; 
      // Ensure both the property and value are 
      // supported and return 
      return support && (el.style[camel] !== ''); 
     }, 
+1

Mögliches Duplikat [Check-Browser CSS-Eigenschaft Unterstützung] kommt (http://stackoverflow.com/questions/1342994/check-browser- CSS-Eigenschaft-Unterstützung) –

Antwort

0

Sie einen Blick auf CSS.supports nehmen kann, die true oder false zurückkehren

var doSupport = CSS.supports('some CSS property', 'value'); 

Aber es gibt einen Haken. IE nicht unterstützt diese Funktion

Alternativ auch Sie modernizr erkunden können, die ein Plugin

Verwandte Themen