themirror
themirror

Reputation: 10287

Simplest Ajax Photo Gallery

I don't think "simplest" is subjective.

Looking for a hostable photo gallery that does nothing but show an image and provide "next image" and "previous image" but all without reloading the page. Obviously precaching would be nice too. PHP, Python, Ruby, or JS.

Upvotes: 0

Views: 1960

Answers (1)

Aleadam
Aleadam

Reputation: 40391

If you want simple, maybe something like this?

<html>
    <body>
        <div>
            <img id="image">
        </img>
        </div>
        <table>
            <tr>
                <td onclick="getImage("previous");">Previous</td>
                <td onclick="getImage("next");">Next</td>
            </tr>
        </table>
        <script type="text/javascript">
          counter = 0;
          nextImage = new Image();
          previousImage = new Image();
          getImage = function(what) {
            if (what === "previous") {counter--;}
            else {counter++;}
            nextImage.src = "http://www.example.com/image?data=" + (counter + 1);
            previousImage.src = "http://www.example.com/image?data=" + (counter - 1);

            document.getElementById("image").src = "http://www.example.com/image?data=" + counter;
          }        
        </script>
    </body>
</html>

Upvotes: 2

Related Questions