我在将图像放入数组并将它们显示在画布对象中时遇到了一些麻烦。
Jscript 片段
canvas = document.getElementById('slideshow');
canvasContent = canvas.getContext('2d');
var elements = document.getElementsByClassName('slides');
for (var index = 0; index <= elements.length; index += 1)
{
arrFoto[index] = elements[index];
}
canvasContent.drawImage(arrFoto[huidigeIndex], 0, 0);
这是 html 文件的一部分
<div class="container">
<div class="slides">
<img src="data/images/slideshow/3.png" />
<img src="data/images/slideshow/4.jpg" />
<img src="data/images/slideshow/5.png" />
</div>
<canvas id="slideshow" width="700" height="300"></canvas>
</div>
我究竟做错了什么?
谢谢!