简体   繁体   English

HTML5画布幻灯片

[英]HTML5 Canvas slideshow

I'm trying to make a slideshow with html5 canvas and found this this which is working. 我试图与HTML5画布幻灯片,发现这该是工作。

Anybody an idea how to get out of the loop? 有人知道如何摆脱循环吗?

  if (counter > maxNum) counter = 0;

Insstead of counter=0; 代替counter = 0; I wanna get out of this loop, but all things I tried didn't work. 我想摆脱这个循环,但是我尝试过的所有方法都没有用。 Anybody an Idea? 有人有主意吗?

Have you tried break; 你尝试过break;break; ?

if (counter > maxNum) {
    ...
    break;
}

Edit: You might also want to try return ? 编辑:您可能还想尝试return

if (counter > maxNum) {
    ...
    return;
}

If you look at the draw code you have this: 如果您查看绘制代码,您将具有以下内容:

this._draw = function() {

    //if the next image will cover the canvas
    //there is no real need to clear the canvas first.
    //I'll leave it here as you ask for this specifically
    ctx.clearRect(0, 0, myCanvas.width, myCanvas.height)
    ctx.drawImage(images[counter++], 0, 0);
    if (counter > maxNum) counter = 0;

    setTimeout(me._draw, 1000); //here we use me instead of this
}

the problem is that you don't have a loop there so break does not work. 问题是您在那里没有循环,因此break无法正常工作。

but you can replace if (counter > maxNum) counter = 0; 但是您可以替换if (counter > maxNum) counter = 0; (this resets the counter) with if (counter > maxNum) return; (这将重置计数器), if (counter > maxNum) return; which exits the function so that setTimeout would not be called. 退出函数,因此不会调用setTimeout

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

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