Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing of CSS "mix-blend-mode"

I want to use CSS's property :

mix-blend-mode: soft-light;

And I will test by Modernizr for fallback bla bla...

Tested :

Modernizr.mixblendmode //undefined
Modernizr.testProp('mixblendmode'); //false
Modernizr.addTest('mixblendmode'); // no-mixblendmode

What am I missing ?

Tested on Firefox, CSS its work, but how to test with Modernizr ?

like image 718
l2aelba Avatar asked Jan 22 '15 11:01

l2aelba


2 Answers

Modernizr doesn't support this currently. From Modernizr/issues/1388:

Unfortunatly, "[...] in some browsers, mix-blend-mode is implemented; the property is valid, the automated tests pass, but no blending actually takes place" - http://blogs.adobe.com/webplatform/2013/09/12/browser-support-matrix-for-css-blending/

like image 26
user247702 Avatar answered Nov 10 '22 19:11

user247702


Got it :

Modernizr.addTest('mix-blend-mode', function(){
    return Modernizr.testProp('mixBlendMode');
});

(or without Modernizr)

if('CSS' in window && 'supports' in window.CSS) {

    var support = window.CSS.supports('mix-blend-mode','multiply');

    /* Add class like Modernizr */
    /* -- jQuery -- */
    $('html').addClass(support?'mix-blend-mode':'no-mix-blend-mode'); // jQuery
    /* -- Pure JS -- */
    document.getElementsByTagName('html')[0].className += support ? ' mix-blend-mode' : ' no-mix-blend-mode';
    /* -- Pure JS (IE9+) -- */
    document.querySelector('html').classList.add(support ? 'mix-blend-mode' : 'no-mix-blend-mode');
}

(or CSS)

@supports(mix-blend-mode:multiply) {

}

Ref : https://dev.opera.com/articles/getting-to-know-css-blend-modes/

Can I use : http://caniuse.com/#feat=css-mixblendmode

like image 143
l2aelba Avatar answered Nov 10 '22 18:11

l2aelba