Good day, here is such a script for a simple gallery, now I don’t quite understand how to get src (in my case alt) for the next image when clicking on NEXT and PREV?!?!?!
1 answer
You have to create another global variable (!) That will be responsible for the current image, for example, currentImage.
In the orImg.on callback, you should, when clicked, assign the currentImage variable a reference to the image tag that was clicked.
In this case, you will always have a link to the current image. And to get the link to the next image, you can use the next function. Well, how to get the alt image in your code is already written.
(!) In fact, creating global variables is not the best practice, but since this code is test, then you can write at least one line :)
- Thank you, I tried to do this but apparently missed something, and I made everything global because of global, because I don’t have a good knowledge of JS and I didn’t get nice, first remove the page, then hide the container with the caritka, then remove the overlay and clean the styles A container with a picture, as the nested callbacks do not see the necessary variables. - Cone
|