我尝试使用此功能将photoswipe JS Image Gallery作为幻灯片放映运行:
function gallery_autoplay() {
gallery.next();
setTimeout(gallery_autoplay(),3000);
}
setTimeout(gallery_autoplay(),3000);
但是ei在photoswipe.js第1088行收到错误
你需要setInterval
而不是setTimeout
function gallery_autoplay() {
gallery.next();
}
setInterval(gallery_autoplay,3000);
你没有包括你的整个代码,但如果我猜测你使用.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);
希望这可以帮助