我想在图像滑块中实现简单的左右箭头导航。以下是我已经尝试过的。如果单击箭头,我必须在哪里放置该功能。 changeImg
函数内部或外部?提前致谢
<div class="slider">
<span id="left"><</span>
<img class="sliderImg" name="slide">
<span id="right">></span>
</div>
var i = 0;
var images = [];
var time = 4000;
images[0] = "img/image1.png";
images[1] = "img/image2.png";
images[2] = "img/image3.png";
function changeImg() {
document.slide.src = images[i];
if (i < images.length - 1) {
i++;
}
document.querySelector("#left").addEventListener("click", function()
{
i--;
});
else {
i = 0;
}
setTimeout("changeImg()", time);
}