有没有方法检查内联svg中的<image>
是否已加载?普通imgs有一个完整的属性来检查<img>
是否已被加载,但不是<image>
。我只想在图像尚未加载的情况下添加加载事件侦听器。检查是否加载了内联SVG图像
以下的Here's a codepen:
<svg width="300" height="300">
<image xlink:href="http://placebeard.it/300/300" width="300" height="300"></image>
</svg>
<script>
var image = document.querySelector('image');
console.log(image.complete) // undefined
if (!image.complete && image.complete != null){ // does not work because there is no complete property of svg image, unlike a regular img
image.addEventListener('load', function(){
alert('image loaded');
});
}
</script>
这应该是 “如果(!image.complete)” 不应该吗? –
修好了,谢谢。 – Dan0
我已将您的代码示例恢复为已损坏的状态,以避免将来对此问题的读者感到困惑。 –