S
S
slavik_kozachok_official2017-06-06 23:41:23
JavaScript
slavik_kozachok_official, 2017-06-06 23:41:23

How to close the photo gallery with the back button on a smartphone?

The essence of the question: how to implement the closing of the photo gallery when the smartphone's back button is pressed? I use a LightGallery gallery on jQuery - I would like that after viewing the photo I could press the back button and the gallery was closed - and now it returns to the previous page ... Perhaps someone can point me in the right direction to solve the problem.

<div class="gym_gallery">
<ul id="lightgallery" id="hash"  class="gallery">
<li  data-src="../img//gym/original_img/01.JPG" data-sub-html="Фитнес клуб">
<a href="#">
    <img src="../img/gym/small_img/01.JPG ">
</a>
</li>
</div>

jQuery(document) .ready(function ($){
  $("#lightgallery") .lightGallery({
  });
  $("#lightgallery01") .lightGallery({
  });
  $('#hash').lightGallery();
});

Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sobko, 2017-06-07
@Catzo0

First you need to learn how to catch the "Back" button click. Here is the first link from Stackoverflow - there is a lot of stuff written there. Click
Next, maybe consider using event.preventDefault() to prevent returning to the previous page.
Also, most likely, it is worth keeping track of the current state of the gallery, so as not to prevent the user from returning to the previous page when the gallery is closed.

A
Arman, 2017-06-07
@Arik

Alternatively, you can slip the previous page without an open gallery through the history API.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question