AngularJS应用中的Svg clipPath, url为hashbang模式
Svg clipPath in AngularJS app with url in hashbang mode
我在AngularJS项目中使用svg clipPath
。这是这个问题的后续问题。
假设我有一个这样的svg:
<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>
因为我使用的是<base>
元素所以不能使用这样的相对路径
<g clip-path="url(#myClip)">
所以我必须使用绝对URL +一个片段标识符,像这样:
<g clip-path="url(http://example.com/mypage#myClip)">
这在Firefox, Safari和Chrome中工作得很好。但我有以下问题与IE:
IE9不支持我使用的html5mode,因此使用hashbangs,绝对url变成
http://example.com/!#/mypage#myClip
, clipPath不起作用。在IE10 + IE11中,当我转到包含SVG的页面时,clipPath不起作用,但如果我刷新页面,它就会起作用。
有什么办法解决IE的问题吗?
IE9不支持我使用的html5mode,因此使用了hashbangs,绝对url变成http://example.com/!#/mypage#myClip和clipPath不起作用
使用xml:base有条件地设置IE9的基础URL:
<g id="xbrowser" clip-path="url(#myClip)">
<circle cx="30" cy="30" r="20"/>
<circle cx="70" cy="70" r="20"/>
</g>
<script type="application/ecmascript">
if ( ("onpropertychange" in document) && !!window.innerWidth)
{
document.getElementById("xbrowser").xmlbase = "http://example.com/!#/mypage"
}
</script>
在IE10 + IE11中,当我转到包含SVG的页面时,clipPath不起作用,但如果我刷新页面,它就起作用了。
以编程方式为IE设置clipPath:
<script type="application/ecmascript">
if (!!window.XPathEvaluator === false && !!window.XPathExpression === false)
{
document.getElementsByTagName("g")[0].clipPath = "url('#myClip')"
}
</script>
引用
XML基础
clipPath属性| clipPath属性
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- 使用php或javascript从facebook相册URL中删除多余的部分
- Angular JS IE9 Hashbang url rewriting
- 我想使用hashbang URL(blah.com/#!/thingtoload)动态加载页面内容(在DIV中),我有j
- hashbang之后的角度替换url
- AngularJS hashbang模式复制URL路径
- 你应该在AJAX内容网站上使用hashbang,还是只使用普通的URL
- 简单的ajaxify,没有hash或hashbang url
- 为hashbang URL验证noscript网站内容
- 在URL中重写hashbang
- AngularJS: Hashbang URL在完全刷新时不断追加到自身
- Url的改变没有hashbang和fragments
- 将谷歌索引正确的URL为hashbang/escaped_fragment内容
- 在刷新时从angularjs的URL中删除hashbang
- Angular JS Hashbang URL's malformed
- AngularJS应用中的Svg clipPath, url为hashbang模式
- 在URL中使用锚点/hashbang来触发加载时的函数
- 使用hashbang方法使用AngularJS提取URL参数
- 角度$location.如果用户提交带有hashbang的URL,如何在html5Mode(true)中解析查询字符串
- 用history.js重定向hashbang到url