Eri*_*röm 14
是的,这是可能的.
在标记中:
<image xlink:href="example.png" width="10" height="10"
onload="alert('loaded')"/>
Run Code Online (Sandbox Code Playgroud)
见jsfiddle.
在脚本中:
<script>
var img = document.createElementNS("http://www.w3.org/2000/svg", "image");
img.addEventListener('load', function() { alert('loaded'); });
// or alternatively:
// img.onload = function() { alert('loaded'); }
img.width.baseVal.value = 100;
img.height.baseVal.value = 100;
img.href.baseVal = "example.png";
</script>
Run Code Online (Sandbox Code Playgroud)
见jsfiddle.
我发现这对使用D3创建的SVG对象不起作用,但这里的答案很有用:
例如,这工作:
var img = innerG.append("image")
.attr('onload', function() {
console.log('loaded');
})
.attr("xlink:href", src)
.attr("width", size)
.attr("height", size);
Run Code Online (Sandbox Code Playgroud)
但这不起作用:
var img = innerG.append("image")
.attr("xlink:href", src)
.attr("width", size)
.attr("height", size);
img.addEventListener('load', function() { console.log('loaded'); });
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11450 次 |
| 最近记录: |