带有next()的PhotoSwipe自动播放

问题描述 投票:0回答:2

我尝试使用此功能将photoswipe JS Image Gallery作为幻灯片放映运行:

function gallery_autoplay() {

    gallery.next();
    setTimeout(gallery_autoplay(),3000);

}

setTimeout(gallery_autoplay(),3000);

但是ei在photoswipe.js第1088行收到错误

javascript slideshow photoswipe
2个回答
1
投票

你需要setInterval而不是setTimeout

function gallery_autoplay() {
    gallery.next();
}
setInterval(gallery_autoplay,3000);

0
投票

你没有包括你的整个代码,但如果我猜测你使用.next()函数的变量是不存在或启动错误。

试试这个:

var gallery; //As a global variable
//then when you init the gallery just use that same variable
//for instance
function OpenPhotoSwipe() {
  var pswpElement = document.querySelectorAll('.pswp')[0];
  var items = [{
    src:'',
    w:1,
    h:1
  }]
  var options = { modal:false,bgOpacity:0.7 };
  gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
  gallery.init();
}
//And then finally use setInterval to queue the transition
setInterval(function() {
  gallery.next();
},3000);

希望这可以帮助

© www.soinside.com 2019 - 2024. All rights reserved.