带有HTML基本元素的AngularJS应用程序中的Svg clipPath

swe*_*edo 12 svg angularjs

clipPath在AngularJS项目中使用了svg .我在为clipPath指定相对url时遇到问题,因为我需要<base>在项目中使用该元素.

例如,此代码可以在项目中使用base,但不能在项目中使用<base href="/">

<svg width="120" height="120"
     viewPort="0 0 120 120" version="1.1"
     xmlns="http://www.w3.org/2000/svg">

    <defs>
        <clipPath id="myClip">
            <rect x="10" y="10" width="60" height="60"></rect>
        </clipPath>
    </defs>

    <g clip-path="url(#myClip)">
        <circle cx="30" cy="30" r="20"/>
        <circle cx="70" cy="70" r="20"/>
    </g>

</svg>
Run Code Online (Sandbox Code Playgroud)

怎么解决这个问题?我使用ui-router,如果这与问题有关...

这个问题大致相同,但OP找到的"解决方案"是删除基础,这在我的情况下不是解决方案.

Rob*_*son 13

更改

<g clip-path="url(#myClip)">
Run Code Online (Sandbox Code Playgroud)

这样您就可以使用绝对URL +片段标识符,而不仅仅是片段标识符.例如url(http://mydomain.com/mypage#myClip)

如果基本标记与绝对URL匹配,您可能能够删除某些部分,例如http和域,因此/ mypage #myClip可能有效.

  • 我使用的解决方法是将`'url'('+ $ location.path()+'#clip)'`之前的相对URL添加到控制器,或者如果你需要它在html中,添加` $ scope.path = $ location.path()`到控制器和`clip-path ="url({{path}}#clip)"`到元素.两者都需要html5mode (5认同)