Sometimes I’ve had to quickly put in a page a simple slideshow, the first times I’ve searched a lot around for a small gallery, but finally I’ve decided that the best way is to do it by myself. This because every complex and very nice gallery that I’ve found need to be studied to make them work as you want, and sometimes they have complex css to integrate or php code to put in the correct directory… I think that many times we all just need a simple php that read a dir, and pass images array to a stupid slideshow.
If you already have JQuery in your pages this gallery is really fast, it works with this small PHP function that find images:
/* this php function read all the jpg/gif/png files in the specifed directory and return a string with the names */ function getJsArray($dir) { $out = ""; if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) if(in_array( substr(strrchr($file, '.'), 1) , array('gif','png','jpg') )) $out.= ($out?",":"")."'".$dir.$file."'"; closedir($dh); } else { die ("no dir"); } return $out; }
And uses this tiny javascript (the first lines are for configuration, they also call the php function on the server to read images files):
//--------------------------------------------- var gallery_current_pos = 0; // gallery counter position var gallery_idname = "container"; // id of the gallery container var gallery_timer = 5000; // 5 seconds var gallery_ar = Array(<?=getJsArray("./minislides/")?>); function goGallery() { if (gallery_current_pos>gallery_ar.length - 1) gallery_current_pos =0; $('#'+gallery_idname).fadeTo("fast", 0 , function () { $('#'+gallery_idname).css("background-image","url(" + gallery_ar[gallery_current_pos] + ")"); $('#'+gallery_idname).fadeTo("slow", 1); gallery_current_pos++; }); if (gallery_ar.length>1) setTimeout( function () { goGallery(); }, gallery_timer); } //---------------------------------------------
The “container” which will show the images is simply a “div” with some defined dimensions declared with css, and the javascript will change its background to show images.
When the page is loaded simply call the function to start gallery.
I’m having a little bit of trouble viewing your site in Safari, but it may just be my computer. Apart from that, I love your site. I plan on browsing around and reading some more posts!