0

到目前为止,PhotoSwipe 非常棒,只是这些我似乎无法解决的小问题

我初始化 PhotoSwipe 如下

formPhoto.gallery = window.Code.PhotoSwipe.attach( images, options);

在图库中,用户可以通过以下方式选择是否删除图像

一旦按下删除按钮,它就会运行

formPhoto.gallery.cache.images.splice(e.target.currentIndex,1);
delete formPhoto.activeObj.value[e.target.originalImages[e.target.currentIndex].id];


if(formPhoto.gallery.cache.images.length == 0)
   formPhoto.gallery.hide();
else 
   formPhoto.gallery.carousel.show( 0 );

现在这几乎可以正常工作,除了 2 种情况。

  1. 如果您低于 3 张照片,它会中断幻灯片事件(在幻灯片右侧) - 图像滑到黑屏上。如果您删除并且只剩下 1 张图像,您甚至无法正确查看图像,它只会弹回黑屏。
  2. 如果您再次将图像重新添加到图库中,则会再次显示已删除的旧图像

它使用重新启动

images = [];
for(var x in formPhoto.activeObj.value)
  images.push({url: formPhoto.activeObj.value[x].file, id:x});

formPhoto.gallery = window.Code.PhotoSwipe.attach( images, options);

如果您愿意,我可以尝试获取正在发生的事情的录音。我不知道如何解决这个问题,我已经在https://github.com/codecomputerlove/PhotoSwipe/issues和谷歌上环顾四周,但没有任何帮助。

我真正想做的只是从图库中删除图像(仅在独占模式下查看)

4

2 回答 2

0

好的,我最终写了一个临时解决方案.. 它有点 hacky,但我只是手动从轮播中删除 DOM

            jQuery(formPhoto.gallery.carousel.contentEl).find("[src*=\"" + formPhoto.activeObj.value[e.target.originalImages[e.target.currentIndex].id].file + "\"]").parent().remove();
            //we look for the image that contains the same filename as the one we're trying to delete.
            //so we just remove that.

            formPhoto.gallery.cache.images.splice(e.target.currentIndex,1);

            delete formPhoto.activeObj.value[e.target.originalImages[e.target.currentIndex].id];
            e.target.originalImages.splice(e.target.currentIndex, 1);


            formPhoto.activeObj.object.find("[type=amountadded]").html(formPhoto.activeObj.valueLength() + " photos");

            if(formPhoto.gallery.cache.images.length == 0)
                formPhoto.gallery.hide();
            else   {
                //real hacky job. Atleast it looks like a real cool effect occured.
                formPhoto.galleryInitiate(formPhoto.activeObj, e.target.originalImages);
            }

还修复了图像重新出现的问题,因为新生成的文件具有相同的文件名。同时在文件名中添加了日期组件。

于 2012-05-10T06:36:24.133 回答
0

这是删除按钮的处理程序

function ps_delete_image(btn) {
    var inst = PhotoSwipe.instances[0];
    var curImg = $photoSwipe.getCurrentImage();
    inst.cache.images.splice(inst.currentIndex, 1);
    inst.originalImages.splice(inst.currentIndex, 1);
    if(inst.cache.images.length == 0) inst.hide();
    else {
        if (inst.currentIndex == inst.cache.images.length) inst.carousel.show(inst.currentIndex - 1);
        else inst.carousel.show(inst.currentIndex);
    }
    // remove delete button if 3 or less is left
    if(inst.cache.images.length <= 3) {
        $(btn).remove();
    }
}

为了克服 3 张或更少图像的问题,我只需删除删除按钮。

于 2014-05-28T09:00:55.850 回答