SVG display difference between <img> and <object>

你。 提交于 2020-01-22 02:26:10

问题


What's the difference between displaying a SVG image in an <img> or <object> tag? I was facing some problems using SVG images in a <img> tag on Android 3.1:

The shape in the upper example is an <img> tag and the lowest example is the exact same image but display in an <object>. Why is this displayed a different way? And is an <object> cached like an <img>?

What do you guys suggest?


回答1:


Differences when SVG is used as an image (html <img> SVG <image> or CSS background images)

  • no scripting
  • no interactivity
  • no external dependencies (complete in a single file)
  • no DOM (i.e. no script access into them from outside)
  • can be copied into canvas via drawImage

I suspect you're suffering from the no external dependencies rule. You may also want to check that the SVG data has a preserveAspectRatio attribute on the root element and if it does that the value of that attribute is not none.



来源:https://stackoverflow.com/questions/30538325/svg-display-difference-between-img-and-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!