refiking Posted May 19, 2009 Share Posted May 19, 2009 How can I take alter this code to retrieve all the images from the images/header folder instead of having to list each one separately? <script language="JavaScript"> // configuration structure var A_TPL = { // randomize the array each time page loads 'random' : true, // number of transparency changes during the transition // increase for smoother transition, reduce for less CPU usage 'steps' : 20, // transition duration in seconds 'transtime': .5, // slide time in seconds 'slidetime': 5, // width of the slide (optional) 'width' : 200, // height of the slide (optional) 'height': 200, // alt text for the image (optional) 'alt' : '', // css class assigned to the slide <img> (optional) 'css' : '' }; // list of images to display var A_ITEMS = [ 'images/masthead.jpg', 'images/header/1.jpg', 'images/header/2.jpg' ]; // fader initialization var mySlideShow = new tFader (A_ITEMS, A_TPL); </script> Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted May 19, 2009 Share Posted May 19, 2009 You could use php to read the files in a folder and output an array of all images in js format. Javascript can't read what files are in a folder. example <script> var jsimages=new Array(); <?php $files=array(); //your read directory script here foreach($files as $file){ //add image urls to the js array echo "jsimages.push('{$file}')\n" ; } ?> </script> Quote Link to comment Share on other sites More sharing options...
refiking Posted May 19, 2009 Author Share Posted May 19, 2009 Hmm. Can you integrate that into the code I pasted? I don't know how it goes together. Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted May 19, 2009 Share Posted May 19, 2009 Keep in mind that the read dir script isnt written in my example however a script to read a folder with images is prob written over a thousand times on this forum I doubt you will have any trouble finding that. As for the array look at the following in your script. // list of images to display var A_ITEMS = [ 'images/masthead.jpg', 'images/header/1.jpg', 'images/header/2.jpg' ]; that's a js array. so A_ITEMS is the array name. Rename jsimages to A_ITEMS and it might work(assuming the php array has the image urls in it). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.