Skip to content
Advertisement

Model Image for gallery function can’t be used on many image

Hello guys so im trying to make model image function for my gallery but I can’t use the function on many image, any suggestion on how fix it ? can I change the var img to collect the element by class name? Thanks before.

Here’s the code:

JavaScript

My CSS Code:

JavaScript

My Java script Code:

JavaScript

Advertisement

Answer

Working with multiple images means working with a collection. For collection work, method forEach works well:

JavaScript

img_curr – the current image from the collection.

Use class modalImg for all img tag.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement