簡體   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