这很新,但无法弄清楚最简单的修补程序是什么?当我在野生动物园中打开页面(通过终端运行本地服务器)时,一切似乎正常。但是,当我刷新页面时,将绘制SVG,但D3交互性不起作用。如果我等待了45秒钟,然后再次刷新,它会起作用。
我有一个简单的index.html,它可以加载使用Illustrator创建的SVG文件。我还引用了带有一些d3代码的非常基本的js脚本。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> test site</title>
<link rel="stylesheet" type="text/css" href="style.css" >
<script type="text/javascript" src="d3.v5.js"></script>
</head>
<body>
<script>
d3.xml('floor.svg')
.then(data => {
d3.select('body').node().append(data.documentElement)
})
</script>
<script src="myScript.js"></script>
</body>
</html>
myScript.js
d3.selectAll("rect")
.on("mouseover", function(){
d3.select(this)
.style("fill", "blue");
})
.on("mouseout", function(){
d3.select(this)
.style("fill", "white")
});