0

我创建了各种 JavaScript 函数来从浏览器中捕获照片。使用 JavaScript 函数,我可以成功启动相机,拍摄照片并预览,然后上传照片。

我正在考虑集成照片定时器功能。在这里,一旦我点击拍照按钮,它将等待 3 秒(例如)并显示一个动画计时器(我正在考虑加载一个动画 gif 文件),它将倒计时 3 到 1。一旦倒计时完成我想调用照片捕捉功能。

但是我无法将这个逻辑集成到我的照片捕捉功能中!

我的示例代码是:

var cameraEnabled = false;
var timer = null;

$('#takeButton').click(function(){

    if(timer != null)
    {
      clearTimeout(timer); 
      timer = null;
    }
    else
    {
        if(!cameraEnabled){
            return false;
        }
        timer = window.setTimeout(webcam.show_image(), 3000);
        webcam.freeze();
        togglePane();
        return false;
    }

});

我的 show_image 函数是:

 show_image:function()
 {
    var img = document.createElement("img");
    img.src = "countdowntimer.gif";
    document.body.appendChild(img);
 },

有人可以帮我解决这个问题吗?

提前感谢您的回复。

4

1 回答 1

1
timer = window.setTimeout(webcam.show_image(), 30000);

执行此操作时,实际上是调用 webcam.show_image,然后将函数结果传递给 setTimeout。要将指针传递给函数,您应该这样做

timer = window.setTimeout(webcam.show_image, 30000);

此外,我认为使用动画 gif 进行文本倒计时并不是一个好主意,您可以在某些 DIV 中操作 innerHTML。最后,30000 毫秒是 30 秒,而不是 3 秒。

于 2013-04-02T13:43:16.253 回答