admin管理员组文章数量:1312680
How to place svg element(rect, circle, etc.,) over html. This is my coding. can anyone help.
<div id="myImgId" style="width: 200px; height: 200px; background:#000;" onmousedown="doSomething()" onmouseup="return false;">
<img src="Chrysanthemum.jpg" width="200" height="200" />
<svg id="svgOne" y="200" width="200" height="200"></svg>
</div>
How to place svg element(rect, circle, etc.,) over html. This is my coding. can anyone help.
<div id="myImgId" style="width: 200px; height: 200px; background:#000;" onmousedown="doSomething()" onmouseup="return false;">
<img src="Chrysanthemum.jpg" width="200" height="200" />
<svg id="svgOne" y="200" width="200" height="200"></svg>
</div>
Share
Improve this question
asked May 30, 2013 at 17:26
chiyangochiyango
43110 silver badges20 bronze badges
2 Answers
Reset to default 7JSFIDDLE: http://jsfiddle/nsgch/
<div id="myImgId" style="width: 200px; height: 200px; background:#000;" onmousedown="doSomething()" onmouseup="return false;">
<img src="Chrysanthemum.jpg" width="200" height="200" style="position:absolute;"/>
<svg id="svgOne" y="200" width="200" height="200" style="position:absolute; left:90px; top:90px;">
<path fill="#014da2" d="M16,1.466C7.973,1.466,1.466,7.973,1.466,16C1.466,24.027,7.973,30.534,16,30.534C24.027,30.534,30.534,24.027,30.534,15.999999999999998C30.534,7.973,24.027,1.466,16,1.466Z"></path>
</svg>
</div>
You can give the elements a style of position: fixed or position: absolute depending on your needs.
<div id="myImgId" style="width: 200px; height: 200px; background:#000;" onmousedown="doSomething()" onmouseup="return false;">
<img style="position:fixed;" src="http://images.nationalgeographic./wpf/media-live/photos/000/005/cache/domestic-cat_516_600x450.jpg" width="200" height="200" />
<svg style="position:fixed;top:50px" id="svgOne" width="200" height="200"><rect width="100%" height="100%" fill="red"/></svg>
</div>
Note that the x and y attributes of outer <svg>
elements are ignored. You'd need to use top and left styles to position it just as you would a html element.
本文标签: javascriptPlace SVG element over img tagStack Overflow
版权声明:本文标题:javascript - Place SVG element over img tag - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741895618a2403558.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论