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とgoogleを調べましたが、役に立ちませんでした。

私が本当にやりたいのは、ギャラリーから画像を削除することだけです(排他モードでのみ表示されます)

4

2 に答える 2

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 に答える
0

わかりました、私は一時的な解決策を書くことになりました..少しハックですが、カルーセルから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 に答える