Animated SVG line animation in IE

I have several path animations on the page and they work fine in all browsers except IE10 / 11. However, I have slightly simpler animations that do the same thing on other pages, only with fewer of them, using pretty much the same code, and they look good.

I think this might be a performance bottleneck or IE related.

If you browse http://codepen.io/jhealey5/pen/YXzbYY in IE10 / 11, you will see that there is a rather noticeable issue where svgs look glitchy or not fully rendered. I cannot understand what it is.

Relevant JS code from codepen:

    var cfg = {
            easing: [0.165, 0.84, 0.44, 1],
            duration: 1200,
            delay: 500,
            layerDelay: 7000,
            width: 28,
            positioning: true,
            colors: [
                    '#027CA5',
                    '#75B5C6',
                    '#00FFD0',
                    '#00B994',
                    '#BEF5FE'
            ]
    }

    $('.shape-layer').each(function(i) {
            var $this = $(this);

            setTimeout(function() {
                    var $paths = $this.find('path');

                    strokeSetup($paths);
                    strokeOut($paths);

            }, cfg.layerDelay * i);
    });

    function strokeSetup($el) {
            $el.each(function(i) {
                    var $this = $(this),
                            pLen = Math.ceil($this.get(0).getTotalLength());

                    $this.css({
                            'stroke-dasharray': pLen,
                            'stroke-dashoffset': pLen,
                            'stroke-width': cfg.width
                    });
            });
    }

    function strokeOut($el) {
            var pathCount = $el.length,
                    iterationCount = pathCount;

            $el.each(function(i) {
                    var $this = $(this),
                            pLen = Math.ceil($this.get(0).getTotalLength()),
                            color = cfg.colors[getRandom(0, cfg.colors.length)];

                    setTimeout(function() {
                            $this.css({
                                    'stroke': color
                            });

                            if (cfg.positioning) {
                                    var side = ['top', 'bottom', 'left', 'right'],
                                            cssO = {};

                                    $this.parent().css({
                                            top: 'auto',
                                            bottom: 'auto',
                                            left: 'auto',
                                            right: 'auto'
                                    });

                                    cssO[side[getRandom(0, 1)]] = getRandom(0, 40) + '%';

                                    var firstPos = cssO[Object.keys(cssO)[0]],
                                            sideAmount = (parseInt(firstPos) < 20) ? 100 : 20;

                                    cssO[side[getRandom(2, 3)]] = getRandom(0, sideAmount) + '%';

                                    $this.parent().css(cssO);
                            }

                            $this.velocity({
                                    'stroke-dashoffset': 0,
                            }, {
                                    duration: cfg.duration,
                                    easing: cfg.easing
                            });

                            if (!--iterationCount) {
                                    strokeIn($el);
                            }
                    }, cfg.delay * i);
            });

    }

    function strokeIn($el) {
            var pathCount = $el.length,
                    iterationCount = pathCount;

            $el.each(function(i) {
                    var $this = $(this),
                            pLen = Math.ceil($this.get(0).getTotalLength());

                    setTimeout(function() {

                            $this.velocity({
                                    'stroke-dashoffset': pLen
                            }, {
                                    duration: cfg.duration,
                                    easing: cfg.easing
                            });

                            if (!--iterationCount) {
                                    strokeOut($el);
                            }
                    }, cfg.delay * i);
            });
    }

    function getRandom(min, max) {
            return Math.floor(Math.random() * (max - min + 1)) + min;
    }

      

+3


source to share


1 answer


You may know this, but All versions of Internet Explorer do not support SMIL Animation of paths / strokes etc. SMIL. Even through JavaScript. And jQuery is not fully SVG DOM compliant. While this manipulation is done via CSS SVG properties, SVG animation via CSS is not ideal.

SMIL is dying and will be depreciated, so I recommend spending more time on libs like Snap.svg (ie9 +) or Raphaël . > (ie6 +), I personally lean more towards Snap.

Anyway, what did you do with this animation?



In your circumstances, from a reasonable professional point of view, this is not a progressive improvement scenario. This means that you have to compensate by turning that SVG animation into a video, gif, or static image and using it as a fallback for IE browsers. for example via modernizr or something else.

It is completely wrong that everything should look the same in every browser. I believe that a static jpg image is sufficient for those lacking features in this scenario.

Another thing I always know about is that regarding SVG, Internet Explorer has "broken" compatibility with the IE version chain.

+2


source







All Articles