画像は経由で描画されます$.ajax
次に、Photoswipeインスタンスが内部に作成されます$.ajax
ユーザーがブラウザの戻るボタンをクリックしたときにPhotoswipeインスタンスをデタッチしようとしましたが、デタッチできませんでした。
誰かがこれを克服するための可能な解決策を知っていますか?
画像は経由で描画されます$.ajax
次に、Photoswipeインスタンスが内部に作成されます$.ajax
ユーザーがブラウザの戻るボタンをクリックしたときにPhotoswipeインスタンスをデタッチしようとしましたが、デタッチできませんでした。
誰かがこれを克服するための可能な解決策を知っていますか?
これがあなたの役に立つかどうかはわかりませんが...
クラス で PhotoSwipe をページにgallery-page
アタッチし、実際の PhotoSwipe インスタンスをgallery
、<a href="../path/image.jpg" rel="external">...</a>
.
また、各ページにIDを付与します。したがって、index.html にはid="gallery1"
.
次に、script.js
PhotoSwipe を.gallery
クラスにアタッチするために実際に呼び出すファイルで、次のように if ステートメント (ページごとに 1 つ) を使用します。
// ..... bunch of JS, including PhotoSwipe core
// Create "exists" function for PhotoSwipe code
jQuery.fn.exists = function(){return this.length>0;}
// Create PhotoSwipe instance for a page that has id="gallery1"
if ($('#gallery1').exists()) {
// Do something
var myPhotoSwipe = $("#gallery1 .gallery a").photoSwipe({
allowUserZoom: false,
backButtonHideEnabled: true,
enableMouseWheel: false,
enableKeyboard: false,
cacheMode: Code.PhotoSwipe.Cache.Mode.aggressive,
captionAndToolbarAutoHideDelay: 0,
captionAndToolbarShowEmptyCaptions: false,
jQueryMobile: true
});
} // .... continue on for other page IDs
これをページごとに行い、特定のページごとに必要なものに応じて PhotoSwipe 設定をカスタマイズします。関数を作ったのでexists
、前回と違うIDのページならPhotoSwipeのインスタンスを削除し、違っていればid="galleryN"
その設定・画像を代わりに貼り付けます。
これがお役に立てば幸いです...お知らせください。
最後に解決策を見つけました。以下を参照してください
$.ajax({ URL: URL_TO_GET_JSON、 成功: 関数 (json, ステータス) { var p = []; $.each(json, 関数(a,b){ // ここに画像を描画します。 }); $('.gallery').html(photo.join('')); // ここでインスタンスを作成 var myPhotoSwipe = $(".gallery a").photoSwipe({ enableMouseWheel: false, })) /************ ここでインスタンスの設定を解除します *****************/ $(document).bind('pagebeforechange', function(e) { if ($('.ps-carousel').length) { $('body').removeClass('ps-active'); var photoSwipe = window.Code.PhotoSwipe; var photoSwipeInstance = photoSwipe.getInstance($(myPhotoSwipe).attr('id')); if (typeof photoSwipeInstance != "未定義" && photoSwipeInstance != null) { photoSwipe.unsetActivateInstance(photoSwipeInstance); photoSwipe.detatch(photoSwipeInstance); } } }); } });