我正在使用 Scala.js和 d3.js ( scala-js-d3 ) 在 Web 应用程序中绘制 SVG。我遇到的问题是,对于我的背景图片,在 iOS (iPhone) 上使用 Chrome 时不会触发 load
事件。在 Windows 上使用 Chrome 时它会触发。图片本身在所有平台上都是可见的。
这是我添加图片的方式:
d3.select("#backgroundImg")
.append("image")
.attr("id", "graphBackgroundImage")
.attr("width", "1954px")
.attr("height", "1532px")
.attr("xlink:href", "img/maps/map.png")
// TODO this load event does not trigger on iOS!
.on("load", (_: EventTarget) => { println("image loaded") } : Unit)
.on("error", (_: EventTarget) => { prinltn("an error has occured") } : Unit)
在 Windows 上,这会创建以下 svg dom 元素(一切都按预期工作):
<g id="backgroundImg">
<image id="graphBackgroundImage" width="1954px" height="1532px" xlink:href="img/maps/map.png"></image>
</g>
在我的 iPhone 上调试有点困难,所以这就是我目前所发现的全部内容。我只知道在 iOS 上使用 Chrome 时未记录 image loaded
(也没有 an error has occurred
日志)。
最佳答案
关于此有一个类似的主题(减去 scala JS),这里是链接:Topic One
这是另一个可能有帮助的方法: Topic Two
解决方案最终是他们有“指定‘指针事件’的 css 属性”
能否发送您的网址以供审核。如果这两个链接都没有帮助,我想我可能会有另一个想法,但我需要查看更多代码。
关于javascript - 在 iOS 上使用 Chrome 不会触发图像 onLoad 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58996240/