Created
April 18, 2018 10:04
-
-
Save mrkkr/5333b2c0d0709d131820525cbe0d84b1 to your computer and use it in GitHub Desktop.
CSS object-fit IE hack (carousel) #html #css #js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) { | |
/* IE10+ CSS styles go here */ | |
img.img-slide { | |
opacity: 0 !important; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="mainSlider" class="carousel slide" data-ride="carousel"> | |
<div class="carousel-inner"> | |
<div class="carousel-item"> | |
<img class="d-block w-100 img-slide" src="" alt="First slide" /> | |
</div> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var userAgent, ieReg, ie; | |
userAgent = window.navigator.userAgent; | |
ieReg = /msie|Trident.*rv[ :]*11\./gi; | |
ie = ieReg.test(userAgent); | |
if(ie) { | |
$(".carousel-item").each(function () { | |
var $container = $(this), | |
imgUrl = $container.find("img").prop("src"); | |
if (imgUrl) { | |
$container.css({"backgroundImage":'url(' + imgUrl + ')', | |
"background-size":"cover", | |
"height":"100vh", | |
"width":"100vw", | |
"max-width":"100%", | |
"background-position":"center"}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment