-
-
Save radioman-00/ae7bf170434200e368b11f75285fa49a to your computer and use it in GitHub Desktop.
Simple image viewer, which loads all images from an html directory listing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> | |
| </head> | |
| <body> | |
| <img id="viewer" src="" width="800px"/> | |
| <div id="info"> </div> | |
| <script> | |
| $(function() { | |
| var baseUrl = "/images/"; | |
| var pictureIndex = 0; | |
| var pictures = []; | |
| function getFiles() { | |
| $.ajax(baseUrl).success(function(data) { | |
| pictures = []; | |
| var lastPicture = ""; | |
| $(data).find("a[href]").each(function() { | |
| var href = $(this).attr('href'); | |
| if (href.indexOf('.jpg') > 0 || href.indexOf('.png') > 0 || href.indexOf('.jpeg') > 0) { | |
| if (href != lastPicture) { | |
| pictures.push(href); | |
| lastPicture = href; | |
| } | |
| } | |
| }); | |
| console.log(pictures.length + " pictures loaded!"); | |
| changePicture(0); | |
| }); | |
| } | |
| function changePicture(indexOffset) { | |
| pictureIndex += indexOffset; | |
| if (pictureIndex >= pictures.length) { | |
| pictureIndex = 0; | |
| } else if (pictureIndex < 0) { | |
| pictureIndex = pictures.length - 1; | |
| } | |
| $('#viewer').attr('src', baseUrl + pictures[pictureIndex]); | |
| $('#info').text((pictureIndex + 1) + "/" + pictures.length); | |
| } | |
| getFiles(); | |
| $(document).keydown(function(e){ | |
| var left = -1, right = 1; | |
| if (e.keyCode == 37) { | |
| changePicture(left); return false; | |
| } else if (e.keyCode == 39) { | |
| changePicture(right); return false; | |
| } | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Author
Thanks. What do we do to use this?
Hi @https://gist.github.com/radioman-00-00. I get nothing at all. Not doubles, not singles. I'm with @https://gist.github.com/ThinkDigitalSoftware: how do we use this? I've tried putting this HTML file in the same directory level as another directory named "images" and putting some .jpgs in there. Not enough though, nothing happening. Hints? Thanks!@
- Scott
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for me I get the every image twice so I have made a fork to the code to fix that.