Jump to content

random order image gallery


goldy19

Recommended Posts

Hello All,

I am having trouble with this image gallery. I cannot seem to get the right lines of code to make it a random order gallery. Could you please point me in the right direction? Thank you so much!

I have 30 images in this gallery. 

 

<script type="text/javascript">
                        var myIndex = 0;
                        carousel();

                        function carousel() {
                            var i;
                            var x = document.getElementsByClassName("mySlides2");
                            for (i = 0; i < x.length; i++) {
                               x.style.display = "none";  
                            }
                            myIndex++;
                            if (myIndex > x.length) {myIndex = 1}    
                            x[myIndex-1].style.display = "block";  
                            setTimeout(carousel, 3000); // Change image every 2 seconds
                        }
                    </script>

Link to comment
Share on other sites

I do not have time to provide you with a complete solution, but I do have a question that might spur you to a different routine.

QUESTION:  What is causing myIndex++; to advance? Or, in other words, how are you calling carousel( )?

Link to comment
Share on other sites

You just need to lose everything related to myindex by commenting out for now, and replace with random function instead so myindex will equal value of random number produced

Math.floor((Math.random() * 10) + 1);

10 will be the total number of class myslides using x.length.

Then make sure  x[myIndex-1].style.display = "block";  is uncommented

2 hours ago, iwato said:

I do not have time to provide you with a complete solution, but I do have a question that might spur you to a different routine.

QUESTION:  What is causing myIndex++; to advance? Or, in other words, how are you calling carousel( )?

It uses a inline called function carousel() on side navigation for manual on event click, and setTimeout(carousel, 3000) to call function every 3000 milliseconds (3 seconds).

Edited by dsonesuk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...