Javascript自动下一张图片
我创建了这个网站,它使用一个简单的 JavaScript 函数来根据用户将鼠标悬停或单击右侧编号框来显示图像。现在,经过测试,确定应在此基础上添加自动幻灯片,以便几秒钟后显示下一张图像。
http://www.philippedollo.com/photo/fineart/f_amw.htm
有没有一种方法可以轻松修改此代码以使其轻松实现? --
function showPic(whichpic) {
if (document.getElementById) {
document.getElementById('placeholder').src = whichpic.href;
if (whichpic.title) {
document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
} else {
document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
}
return false;
} else {
return true;
}
}
I created this site which uses a simple javascript function to show images based on the user mousing over or clicking numbered boxes on the right. Now after testing it's been determined that an automatic slideshow should be added on top of this, so that next image will show after a few seconds.
http://www.philippedollo.com/photo/fineart/f_amw.htm
Is there a way to amend this code easily to make it happen easily? --
function showPic(whichpic) {
if (document.getElementById) {
document.getElementById('placeholder').src = whichpic.href;
if (whichpic.title) {
document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
} else {
document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
}
return false;
} else {
return true;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
setInterval()
。不需要
if(document.getElementById)
检查,因为该函数是 100% 跨浏览器的。Use
setInterval()
.There's no need for the
if(document.getElementById)
check, since the function is 100% cross-browser.以下内容应该适合您,我测试了它并且在我这边工作得很好。
The following should work for you, I tested it and it works fine on my end.