Load next Images via Ajax and add to Fancybox

喜欢而已 提交于 2019-11-29 08:39:25

OK, just for fun and based on imran-a's comment at this GitHub issue, here is your hacked solution :

$(".fancybox").fancybox({
    loop: false,
    beforeLoad: function () {
        if ((this.index == this.group.length - 1) && !done) {
            ajaxGetNextImages();
            done = true;
            this.group.push(
               { href: "images/04.jpg", type: "image", title: "Picture 04", isDom: false },
               { href: "images/05.jpg", type: "image", title: "Picture 05", isDom: false },
               { href: "images/06.jpg", type: "image", title: "Picture 06", isDom: false }
            ); // push 
        } // if
    } // beforeLoad
}); // fancybox

NOTICE that apart from calling ajaxGetNextImages() (which places the new images in the document flow) I had to push (manually) the new images inside the fancybox's group.

Is not a perfect solution but it works, see DEMO HERE; you will see three thumbnails at page load. Once you open fancybox and navigate to the last item, three more thumbnails will be added to the document as well as the 3 corresponding images to the fancybox gallery.

Also notice that you have to initialize var done = false; at the begining of your script.

BTW, forget about the function loadFancybox(),no needed.

try calling .fancybox(); again after loading images dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!