简体   繁体   English

尝试实现平移和缩放功能时,Safari上未显示D3.js V4图片

[英]D3.js V4 image not shown on safari, when trying to implement pan and zoom feature

I am trying to implement panning and zooming feature using d3.js, everything is working fine, but when I try to run the same code on Safari the image is not displayed. 我正在尝试使用d3.js实现平移和缩放功能,但一切正常,但是当我尝试在Safari上运行相同的代码时,则不会显示图像。

The recreation of the issue (Please run it in safari): 重新发布该问题(请在野生动物园中运行):

 let imgHeight = 400, imgWidth = 900, width = 900, height = 450; let zoom = d3.zoom().scaleExtent([1, 8]).on("zoom", zoomed); let svg = d3.select("#canvas").append("svg") .attr("width", width + "px") .attr("height", height + "px"); svg = svg.append("g") .attr("transform", "translate(0,25)") .call(zoom) .append("g"); svg.append("image") .attr("width", imgWidth + "px") .attr("height", imgHeight + "px") .attr("href", "https://www.w3schools.com/howto/img_fjords.jpg"); function zoomed() { svg.attr("transform", d3.event.transform); } 
 <div id='canvas'> </div> <script src="https://d3js.org/d3.v4.min.js"></script> 

I just need to change attribute href in image tag as xlink:href , now it's working fine. 我只需要将图像标签中的属性href更改为xlink:href ,现在就可以正常工作了。

 let imgHeight = 400, imgWidth = 900, width = 900, height = 450; let zoom = d3.zoom().scaleExtent([1, 8]).on("zoom", zoomed); let svg = d3.select("#canvas").append("svg") .attr("width", width + "px") .attr("height", height + "px"); svg = svg.append("g") .attr("transform", "translate(0,25)") .call(zoom) .append("g"); svg.append("image") .attr("width", imgWidth + "px") .attr("height", imgHeight + "px") .attr("xlink:href", "https://www.w3schools.com/howto/img_fjords.jpg"); function zoomed() { svg.attr("transform", d3.event.transform); } 
 <div id='canvas'> </div> <script src="https://d3js.org/d3.v4.min.js"></script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM