Now I will try to explain everything ...
<div id="imageContainer"></div> // html, тут миниатюрмы будут <img id="realSizeImg"> // тут реальный размер картинки после клика по миниатюре
-
#imageContainer img{ // css, делаем миниатюры и отступ между ними width: 10%; height: 10%; margin:10px; }
-
var imagesArray = new Array("1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg"); //массив с изображениями var imgCounter = 0; //счетчик, с помощью которого будем бегать по элементам массива window.onload = function () { var imageContainer = document.getElementById("imageContainer"); //где будут миниатюры for (var i = 0; i < imagesArray.length; i++) { //вытаскиваем все картинки var imgElement = document.createElement("IMG"); //создаем элементы <IMG> imgElement.src = imagesArray[i]; //каждому присваиваем линк на картинку imgElement.onclick = openRealSize; //при клике на миниатюру, запускаем функцию, которая открывает оригинал картинки в другом DIVe imageContainer.appendChild(imgElement); //прикрепляем <img> к родительскому контейнеру с миниатюрами } } function openRealSize() { var realSizeImgDiv = document.getElementById("realSizeImg"); //ищем <img> елемент, где будет открываться оригинал изображения realSizeImgDiv.src = this.src; //присваиваем ссылку на картинку }
Also imagine that we have 2 buttons "Forward" and "Back", and 2 functions, respectively, to realize the transition to the picture forward or backward. In them we used our imgCounter counter to make the array "cyclical", i.e. if the user is sitting in the picture 0 of the array element and presses back - we throw it at the very end of the array, and vice versa ... if at the end he presses Forward - we throw it at the very beginning of the array.
Now such a question is how to force the IMGamer imgCounter to assign the element number of the imagesArray in the image when clicking on the thumbnail. In order to click on the thumbnail ... by pressing the "left" and "right" buttons, it switches 1 back from the selected thumbnail or respectively 1 forward from the thumbnail.
I thought in the openRealSize function somehow through this assign ... failed.