我试图弄清楚它试图从下面的代码中得到什么:
var svg = document.querySelector('svg'),
path = document.querySelector('path');
var code = document.querySelector('#code');
上面引用的代码是:
<textarea id="code">var curve = new CurveAnimator(
[206,47], [182,280],
[90,234], [273,101]
);
var o = document.getElementById('img');
o.style.position = 'absolute';
curve.animate(2, function(point,angle){
o.style.left = point.x+"px";
o.style.top = point.y+"px";
o.style.transform =
o.style.webkitTransform =
o.style.MozTransform =
"rotate("+angle+"deg)";
});
</textarea>
<section>
<svg viewBox="0 0 450 370" width="400px" height="370px" xmlns="http://www.w3.org/2000/svg" class="content">
<path d="M50,300 C50,100 350,100 350,300 " />
</svg>
</section>
目标是获取这些 HTML 代码并将其放置在 javascript 本身中,这样它就不会在 HTML 代码的标签中查找它。但是,我无法找出它从那些querySelector中得到了什么,以便我自己去做。
任何帮助都会很棒!
当我做alert(document.getElementById('code')); 我明白了:
代码串:
var code = "var curve = new CurveAnimator([206,47], [182,280],[90,234], [273,101]);var o = document.getElementById('img');
o.style.position = 'absolute';curve.animate(2, function(point,angle){o.style.left = point.x+""px"";o.style.top = point.y+""px"";o.style.transform = o.style.webkitTransform =o.style.MozTransform =""rotate("" + angle + ""deg)"";});"