2016-12-30 79 views
0

我儘量讓運行幻燈片播放的photoswipe JS圖片廊,使用此功能:PhotoSwipe自動播放旁邊()

function gallery_autoplay() { 

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

} 

setTimeout(gallery_autoplay(),3000); 

但在EI的photoswipe.js 1088線得到一個錯誤

+0

我覺得一個人好解釋指鏈接http://stackoverflow.com/questions/27841324/photoswipe-is-there-a-way-to -attach-AN-事件處理程序至所述-INIT-事件或-WHE –

回答

0

您需要setIntervalsetTimeout

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

你是不是包括你的整個代碼,但如果我是以此來猜測這將是該變量使用的.next()函數O n不存在或者啓動錯誤。

試試這個:

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); 

希望這有助於