-
-
Save modjke/3b8b3f11490ddf6d1bda18f8a9d44d1a to your computer and use it in GitHub Desktop.
Lottie, automatically fixing SVG scaling issue on Internet Explorer 11, but it's actually runnable on Internet Explorer 11 and no jQuery
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
function lottieIeFixer (el, perspective) { | |
if (typeof perspective === 'undefined') { | |
perspective = 'width'; | |
} | |
if (!window.navigator.userAgent.indexOf('Windows') > -1 && | |
!window.navigator.userAgent.indexOf('rv:11.0') > -1) { | |
return; | |
} | |
var width = el.clientWidth; | |
var height = el.clientHeight; | |
var svg = el.querySelector('svg'); | |
if (perspective === 'width') { | |
var ratio = width / svg.width; | |
svg.width = width; | |
svg.height = svg.height * ratio; | |
} else if (perspective === 'height') { | |
var ratio = height / svg.height; | |
svg.height = height; | |
svg.width = svg.width * ratio; | |
} | |
} | |
// Usage | |
var el = document.querySelector('.lottie-animation'); | |
var animation = lottie.loadAnimation({ | |
container: el, | |
renderer: 'svg', | |
autoplay: true, | |
loop: true, | |
path: el.getAttribute('data-source') | |
}); | |
animation.addEventListener('DOMLoaded', function () { | |
lottieIeFixer(el); | |
}); |
there's still jquery on line 35 m8
tank ya m8, fixd dat
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
there's still jquery on line 35 m8