1

So when the user clicks on an image with a Gallery and decides to view an Image and closes the Gallery the Browser Window brings him to the top of the page.it's not good for accessibility.the focus should move back to it's original position in the page.

Do you have any Idea what could cause and how to controll the focus? I think it has to do with the URL hash added by the Gallery?

what I have checked so far...

Photoswipe docs - changed options >history- false: did not help:(

I have to tried to attach a listener and set focus manually :it did not listen:(

 var pswp = new PhotoSwipe(/* ... */);
 pswp.listen('close', function() { console.log'check 123';});
turcospeed
  • 23
  • 5
  • I use Photoswipe and it does not get me to the top of the page, works without any problems. Is it possible you change body overflow and it takes you to the top? – Ergec Apr 27 '17 at 05:10
  • Hi Ergec :) what do you mean by "change body overflow"? – turcospeed May 01 '17 at 02:29

1 Answers1

1

I had the same problem with Cordova and iOS.

First follow the example at http://photoswipe.com/documentation/getting-started.html and search for the line with the comment

// Pass data to PhotoSwipe and initialize it

After call for the method "gallery.init()" add the next code

gallery.listen('close', function() {
// Here use something for detect the device or just delete the IF 
if (isIOS) {
    //if iOS scroll to img/element
    var _top = $(this.currItem.el).offset().top - 100;
    setTimeout(function() {
        $('html, body').stop().animate({
            scrollTop: _top
        }, 500);
        //$.mobile.silentScroll(_top);
    }, 500);
}}); 

The final code.

var openPhotoSwipe = function(index, galleryElement, disableAnimation, fromURL) {

// ...
// ...

// Pass data to PhotoSwipe and initialize it
gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
gallery.init();

gallery.listen('close', function() {
    // Here use something for detect the device or just delete the IF 
    if (isIOS) {
        //if iOS scroll to img/element
        var _top = $(this.currItem.el).offset().top - 100;
        setTimeout(function() {
            $('html, body').stop().animate({
                scrollTop: _top
            }, 500);
            //$.mobile.silentScroll(_top);
        }, 500);
    }
}); };
Víctor
  • 51
  • 4