Dynamically adding a SVG gradient

前端 未结 4 633
庸人自扰
庸人自扰 2020-12-10 05:38

I have this SVG container with paths. I want to edit it, so the paths\' fill will be a pattern. This is my failed attempt:

I add a gradient:

$(\'svg          


        
4条回答
  •  感动是毒
    2020-12-10 05:59

    Found a solution. It's a bit ugly, but doesn't require the use of additional plugins.

    Apparently, a pattern has to be included in the tag when the SVG is first created (it's probably only read then).

    Thus, replacing the SVG tag's wrapper's contents with themselves works (base being that wrapper):

    $(base).html($(base).html())
    

提交回复
热议问题