繁体   English   中英

通过用户控制时间间隔创建相册

[英]create photo gallery with controlled time interval by user

我已阅读该课程: http : //html.net/tutorials/javascript/lesson17.php ,其中包含一个示例: http : //html.net/tutorials/javascript/lesson17_ex1.html,但是我需要使用可以根据用户在照片之间选择时间,因此我想修改该行代码:

galleryStarter = setTimeout("startGallery()", 2000);

成为用户想要的,所以我添加:

<input type="text" name="name" id="name"><br>   
<input type="button" id="btnSub" value="User gallery"/>
<input type="button" id="btnSub" value="User gallery"/>

也:

var btnStart = document.getElementById("btnStart");
var btnStop = document.getElementById("btnStop");
var btnSub  = document.getElementById("btnSub");

btnStart.onclick = startGallery;
btnStop.onclick = stopGallery;
btnSub.onclick = userGallery;

和:

function userGallery()
{
curImage.src = preloadedImgs[counter].src;
counter ++;
if (counter == preloadedImgs.length)
{
counter = 0;
}
var c=document.getElementById("name").value;
galleryStarter = setTimeout("userGallery()", c);
window.alert(c);
isGalleryOn = true;
}

但是身份证没有用..是什么原因?

这是因为您没有清除以前的计时器。

clearTimeout(galleryStarter);
isGalleryOn = false;

内部function userGallery()将解决您的问题。

在这里检查小提琴。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM