Skip to content

Instantly share code, notes, and snippets.

@modjke
Forked from adriandmitroca/app.js
Last active September 24, 2020 12:49
Show Gist options
  • Save modjke/3b8b3f11490ddf6d1bda18f8a9d44d1a to your computer and use it in GitHub Desktop.
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
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);
});
@modjke
Copy link
Author

modjke commented May 6, 2020

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