Converting Image SVG to Inline SVG using javascript/jquery

自闭症网瘾萝莉.ら 提交于 2019-12-24 06:33:18

问题


Trying to determine how I can include a prefix....such as "tst-" I am trying to prevent this script from interfering with any svg I do not want converted to inline.

This example Works: <img src="image.svg" alt="test image" />

Console.log displays <img src="image.svg" alt="test image" style="display: none;" />

Would like this to work by identifying tst with a .svg: <img src="tst-image.svg" alt="test image" />

Would like console.log to identify any .svg with tst- such as this <img src="tst-image.svg" alt="test image" style="display: none;"/>

    init: function() {
    /* svg to inline */
    (function() {
        $(function() {
            var t;
            return (t = $('img[src$=".svg"]').hide(), t.each(function(t, e) {
            console.log(e);
                var r = this;
                return $.get(this.src).success(function(t) {
                    var e, n, s, i, c, a, u;
                    for (e = $(t).find("svg"), c = r.attributes, $.extend(c, e[0].attributes), a = 0, u = c.length; u > a; a += 1) {
                        n = c[a], s = n.nodeName, i = n.nodeValue, "src" !== s && "style" !== s && e.attr(s, i);
                    }
                    return $(r).replaceWith(e);
                });
            }));
        });
    }).call(this);

}

I hope this makes sense.

来源:https://stackoverflow.com/questions/52540329/converting-image-svg-to-inline-svg-using-javascript-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!