简体   繁体   English

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

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

I have read that lesson: http://html.net/tutorials/javascript/lesson17.php which contains an example: http://html.net/tutorials/javascript/lesson17_ex1.html but I need to create a photo gallery with possibility to choose time between photos by user, so I want to modified that line of code: 我已阅读该课程: http : //html.net/tutorials/javascript/lesson17.php ,其中包含一个示例: http : //html.net/tutorials/javascript/lesson17_ex1.html,但是我需要使用可以根据用户在照片之间选择时间,因此我想修改该行代码:

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

to be as user want, so I add: 成为用户想要的,所以我添加:

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

also: 也:

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

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

and: 和:

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;
}

but id didn't work.. what is the reason? 但是身份证没有用..是什么原因?

It is because you didn't clear previous timer. 这是因为您没有清除以前的计时器。

clearTimeout(galleryStarter);
isGalleryOn = false;

Inside function userGallery() will solved your issue. 内部function userGallery()将解决您的问题。

Check Fiddle Here. 在这里检查小提琴。

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

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