Simplest Ajax Photo Gallery

浪尽此生 提交于 2019-12-02 18:59:50

问题


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.


回答1:


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>


来源:https://stackoverflow.com/questions/5628108/simplest-ajax-photo-gallery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!