I am backing up for object-fit using Modernizr. The solution works, but instead of applying it only to browsers that don't support object-fit (like IE), it applies the code to all browsers. Why is this?
My code is:
if ( ! Modernizr.objectfit ) { console.log('object fit is not supported'); tpj('.featuredpost').each(function () { var $container = tpj(this), imgUrl = $container.find('.img-responsive').prop('src'); if (imgUrl) { $container .css('backgroundImage', 'url(' + imgUrl + ')') .addClass('compat-object-fit'); } }); tpj('.big-post').each(function () { var $container = tpj(this), imgUrl = $container.find('.img-responsive').prop('src'); if (imgUrl) { $container .css('backgroundImage', 'url(' + imgUrl + ')') .addClass('compat-object-fit'); } }); }else{ console.log('object is supported'); }
No matter which browser I check, it always registers: object fit is not supported even in browsers that support object-fit .
What can i do with this?
Modernizr is properly enabled and uploaded (even if I change the local file to the CDN path, I get the same result):
<script type="text/javascript" src="js/modernizr.min.js"></script>

source share