One approach is to surround the gallery position with HTML anchors so that when a user clicks, the browser jumps to that location:
<a id="alexandru-zdrobau-200768-unsplash"></a>
Create all the necessary anchors in this manner. This way, the browser will smoothly navigate to the anchor's position without affecting the gallery JavaScript code.
Another option involves modifying the gallery's code to recognize the URL hash (anchor in the URL) and replacing links with href="javascript:thatfunction('anchor')". Please provide details about the code or gallery you are using for further guidance on this method.
If you prefer an event-controller solution as proposed, ensure that the click events controllers you defined are actually being called. If not, there may be no elements matching the jQuery selectors during setup.
To address this issue, you can:
- Delay your event controller setup (not ideal but necessary sometimes)...
- Implement a global body event controller to determine which events should be prevented by analyzing the event.target property, which identifies the DOM element triggering the event. Check if it's the "a" tag or its parent element (to handle cases where children trigger the event). If this doesn't work, consider using mousedown/touch events instead.