Search code examples
photoswipe

Change start index when the user changes the active image


Does anyone know how to change the start index when the user changes the active image on my website so that PhotoSwipe starts at that image when it is loaded. In other words how I can pass a 'new' index number to PhotoSwipe?


Solution

  • Solved this by using browser history and an onclick event. When they click on a different thumbnail it changes the browser history and PhotoSwipe reads this to zoom the correct image. Example:

    onclick="history.replaceState( {} , 'PAGE TITLE HERE', '#foo&gid=1&pid=INDEX' );"
    

    Replace PAGE TITLE HERE with the page title and replace INDEX with the new images index.