SVG的marker-end顯示不出來的問題

問題描述:
用d3畫的圖,svg和div重疊畫的,svg畫連線和箭頭,div上用d3來append出個性化的展示面板,項目首頁有 <base href="/">,d3生成的svg的標籤文件單獨複製出來後可以看到箭頭(marker-end)!

解決方案

The HTML element is used to say “resolve all relative URLs relative not to this page, but to a new location”. In your case, you’ve told it to resolve relative to the directory with the HTML page.

The SVG marker-mid=”url(…)” attribute is a FuncIRI Reference. When you use a value like url(#foo) that relative IRI is normally resolved relative to the current page, finding the element with the foo id. But, when you use , you change where it looks.

To solve this problem, use a better value. Since your base reference is the current directory, you can simply use the name of the current file:

<line … marker-mid="url(this_page_name.html#arrow)" />

If you have a different href, than what you’ve shown, like:

<base href="http://other.site.com/whee/" />

then you will need to use an absolute href, e.g.

<line … marker-mid="url(http://my.site.com/this_page_name.html#arrow)" />

如果用的Angular, 可以用$location.path!

發佈了198 篇原創文章 · 獲贊 63 · 訪問量 48萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章