<script>
var pics = [
"image/city (1).jpg",
"image/city (2).jpg",
"image/city (3).jpg",
"image/city (4).jpg",
"image/city (5).jpg",
"image/city (6).jpg",
"image/city (7).jpg",
"image/city (8).jpg",
"image/beach.jpg",
"image/beach2.jpg"
];
var inval;
var photo;
function carousel() {
photo = document.getElementById('carousel-pics');
var i = -1;
inval = setInterval(function() {
i++;
if (i >= pics.length) {
i = 0;
}
photo.src = pics[i];
}, 1000);
}
function removeInterval() {
clearInterval(inval);
}
document.getElementById('carousel-pics').addEventListener("mouseover", removeInterval);
</script>
<div class="polaroid" id="carousel-div" style="width:1000px; height:600px;">
<img id="carousel-pics" src="image/city (1).jpg" alt="athens" style="width:1000px; height:600px;">
</div>
上面的代码是一些照片的幻灯片放映。当我将鼠标悬停在照片上时,我想停止幻灯片放映。但这不起作用。如果我添加一个按钮来停止幻灯片放映,它可以工作,但是当我使用鼠标悬停事件时,它不起作用。
梵蒂冈之花
三国纷争
相关分类