Direct to a particular gallery using Javascript

Asked

Viewed 21 times

0

I have 3 galleries being represented in Javascript, each of the galleries shows 4 main photos with the option "see more" next. I want you to click on the option, open a new window showing all photos of the img folder with the name assigned to gallery 1. For example, gallery 1 has photos with names "foto1, foto2, foto3, foto4, foto5, foto6...", I want to click on "see more" direct to another page with all gallery 1 photos in it. and if you click on the "see more" next to gallery 2, upload all the photos from gallery 2, which have, for example, the names of "other1, other2, other3" etc... could you help me ? Here are the codes: The function that loads the main images in the galleries:

window.onload = function(){

        var galeria = new Array();

        var imgs = $("#gallery");
        var x = 1;

        while(x <= 3){

            imgs.innerHTML += "<div class='row'>";
            imgs.innerHTML += "<div class='eight columns'>";
            imgs.innerHTML += "<h4>Galeria "+x+"</h4>"

        for(i = 0; i <= 3; i++){
            galeria[i] = "foto"+x+"_"+(i+1)+".jpg";
        }
        for(i = 0; i < galeria.length; i++){
            imgs.innerHTML += "<img src='img/"+galeria[i]+"' class='imgs-galeria'>";
        }

        imgs.innerHTML += "</div>";
        imgs.innerHTML += "</div>";
        x++;
        imgs.innerHTML += "<a><div id='link' onclick='maisGaleria("+x+");'><p>Veja mais</p></div>";
    }

The function of the option "see more" that directs nothing, just override the previous Divs:

function maisGaleria(n){

    var galeria = new Array();
    var imgs = $("#gallery");

        imgs.innerHTML = "<div class='row'>";
        imgs.innerHTML += "<div class='six columns'>";
        imgs.innerHTML += "<h4>Galeria"+n+"</h4>";

        for(i = 0; i <= 3; i++){
            galeria[i] = "foto"+n+"_"+(i+1)+".jpg";
        }

        for(i = 0; i < galeria.length; i++){
            imgs.innerHTML += "<img src='img/"+galeria[i]+"' class='imgs-galeria'>";
        }

        imgs.innerHTML += "</div>";
        imgs.innerHTML += "</div>";
}
  • I’m having a hard time understanding the question, I think some examples would help. Like, "when typing 1,3,2 in the text field, the element #gallery must receive the images foto1_1.jpg, foto1_2.jpg, foto1_3.jpg, foto3_1.jpg ... foto2_3.jpg" (Just one example, I didn’t understand any of the logic you want). P.S. Always use var when declaring its variables, in its code the i for example is a global one; and if possible, fix the identation of your code example, that section where the for still appears within the while confused me (it looks like it’s out).

  • Corrected! Made it easier to understand ? Thank you !

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.