Slideshow in FancyBox Image Gallery?

后端 未结 3 1728
独厮守ぢ
独厮守ぢ 2020-12-12 01:49

I am just starting out learning some HTML and javascript (read: I know practically nothing about this stuff) and would like to have my index.html page open a rotating image

3条回答
  •  忘掉有多难
    2020-12-12 02:09

    You can add this to the end of your javascript:

    setInterval($.fancybox.next, 10000);
    

    The number represents the waiting time, in milliseconds (so in my example it's 10 seconds). Also, be sure, in the options of the fancybox, to specify cyclic = true, or else it will stop at the last image. (unless that's what you want)

    edit: To add a pause you could do something like the following:

    Instead of that one line in your javascript, add this:

    var rotatingInterval = FALSE;
    function toggleRotating(fromButton) {
      if (rotatingInterval) {
        clearInterval(rotatingInterval);
        rotatingInterval = FALSE;
      } else {
        rotatingInterval = setInterval($.fancybox.next, 10000);
        if (fromButton)
          $.fancybox.next();
      }
    }
    toggleRotating(FALSE);
    

    And then you can have a button in your html, like this:

    
    

    Which would do play/pause.

提交回复
热议问题