Svg中添加dom節點

Reason

相對於svg預約義的形狀元素,dom元素能夠直接使用css調整表現。所以在某些場景咱們須要在svg中插入dom元素css

Solution

首先插入foreignObject元素,而後再插入dom元素,例如:(這裏使用d3js)html

index.htmlbash

<svg></svg>
複製代碼

index.jsapp

import d3 from 'd3';
d3.select('svg')
.append('foreignObject')
.append('div')
複製代碼

參考資料:stackoverflow.com/questions/1…dom

相關文章
相關標籤/搜索