我正在尝试复制this codepen,但出现错误:
tank.js:441 Uncaught TypeError: Cannot read property 'getBBox' of null
at AnalogTank.calculateArrowPosition (tank.js:441)
at AnalogTank.applyArrowAttribute (tank.js:408)
at AnalogTank.addArrow (tank.js:404)
at AnalogTank.initTower (tank.js:316)
at AnalogTank.init (tank.js:126)
at new AnalogTank (tank.js:113)
at jQuery.fn.init.$.fn.analogTank (tank.js:105)
at tank.js:1124
似乎src =“ https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.3/d3.js”>中的d3版本可能是问题的一部分,但我不知道如何纠正错误。
这是我的HTML头供参考。
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.3/d3.js"></script>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>
<script type="text/javascript" src="tank.js"></script>
<link rel="stylesheet" href="tank.css" />
</head>
答案 0 :(得分:0)
在加载HTML之后,我才应该尝试加载tank.js。我只是将tank.js的标签移到了文档的底部。