If i click on any of the thumbnails i have in my gallery, the full screen version of the image will not pop up. The only way it works is if i add [0] after the getElementsByTagName("img"), but only if i click on the first image.
The problem is that gallery.getElementsByTagName("img")
returns a list of all img
-elements in gallery
. Ẁhen you add the [0]
, you select the first element from that list.
Instead, you need to apply the onclick handler function to all elements in that list:
var images = gallery.getElementsByTagName("img");
for (var i = 0; i < images.length; i++) {
images[i].onclick = function() {
// ...
}
}
How to launch Fullscreen:
You can use the Fullscreen API in your JavaScript to make elements fullscreen.
Just call this (for an element called foo):
foo.requestFullscreen();
Here is a simple demo: https://jsfiddle.net/9ytq2dr4/ (Edit: Corrected link)
What I would do is design an initially invisible <div>
that can be displayed fullscreen and contain the full sized image. In the onclick
event of an image in the gallery, you would need to load the full sized version of the clicked image into that div and make it visible and fullscreen.