gameonedne
03-13-2012, 11:58 PM
Hi everyone!
My slide show doesn't preload correctly.
I have a slideshow made with Javascript. It uses PHP to automatically load images in it from a folder.
it consists of a php file that resides in the image folder and a html page with the javascript code that contains the slide show and a image preloader. but the images don't load well. And I can't figure out the mistake.
I don't expect any instant solutions, but some advice would be very appreciated.
the php file:
<?
//PHP SCRIPT: getimages.php
Header("content-type: application/x-javascript");
//This function gets the file names of all images in the current directory
//and ouputs them as a JavaScript array
function returnimages($dirname=".") {
$pattern="/(\.jpg$)|(\.png$)|(\.JPG$)|(\.jpeg$)|(\.gif$)/"; //valid image extensions
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(preg_match($pattern, $file)){ //if this file is a valid image
//Output it as a JavaScript array element
echo 'galleryarray['.$curimage.']="'.$file .'";';
$curimage++;
}
}echo 'var totalamount ="'.$curimage.'";';
closedir($handle);
}
return($files);
}
echo 'var galleryarray=new Array();
'; //Define array in JavaScript
returnimages() //Output the array elements containing the image file names
?>
the HTML file:
<head>
<link type="text/css" rel="stylesheet" href="style.css"/>
<script src="images/slideshow2/getimages.php"></script>
<script language=”javascript”>
var imageObject = new Image();
for(i=0; i<totalamount; i++ )
{
imageObject.src = "images/slideshow2/"+galleryarray[i];
}
</script>
<script type="text/javascript">
var curimg=0
function rotateimages(){
document.getElementById("slideshow").setAttribute("src", "images/slideshow2/"+galleryarray[curimg])
curimg=(curimg<galleryarray.length-1)? curimg+1 : 0
if (document.getElementById) document.getElementById("CaptionBox").innerHTML= galleryarray[curimg];
}
window.onload=function(){
setInterval("rotateimages()", 3700)
}
</script>
</head>
<div style="width: 500px;">
<img id="slideshow" src="images/slideshow2/image1.jpg"/ width=500>
</div>
<div style="
-webkit-transform: rotate(-90deg); -moz-transform: rotate(-90deg); -moz-transform-origin: bottom left; filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=2);"
id=CaptionBox class=Caption>
<a> This is the default caption.
</a> </div>
VERY CURIOUS :D
best Sam
My slide show doesn't preload correctly.
I have a slideshow made with Javascript. It uses PHP to automatically load images in it from a folder.
it consists of a php file that resides in the image folder and a html page with the javascript code that contains the slide show and a image preloader. but the images don't load well. And I can't figure out the mistake.
I don't expect any instant solutions, but some advice would be very appreciated.
the php file:
<?
//PHP SCRIPT: getimages.php
Header("content-type: application/x-javascript");
//This function gets the file names of all images in the current directory
//and ouputs them as a JavaScript array
function returnimages($dirname=".") {
$pattern="/(\.jpg$)|(\.png$)|(\.JPG$)|(\.jpeg$)|(\.gif$)/"; //valid image extensions
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(preg_match($pattern, $file)){ //if this file is a valid image
//Output it as a JavaScript array element
echo 'galleryarray['.$curimage.']="'.$file .'";';
$curimage++;
}
}echo 'var totalamount ="'.$curimage.'";';
closedir($handle);
}
return($files);
}
echo 'var galleryarray=new Array();
'; //Define array in JavaScript
returnimages() //Output the array elements containing the image file names
?>
the HTML file:
<head>
<link type="text/css" rel="stylesheet" href="style.css"/>
<script src="images/slideshow2/getimages.php"></script>
<script language=”javascript”>
var imageObject = new Image();
for(i=0; i<totalamount; i++ )
{
imageObject.src = "images/slideshow2/"+galleryarray[i];
}
</script>
<script type="text/javascript">
var curimg=0
function rotateimages(){
document.getElementById("slideshow").setAttribute("src", "images/slideshow2/"+galleryarray[curimg])
curimg=(curimg<galleryarray.length-1)? curimg+1 : 0
if (document.getElementById) document.getElementById("CaptionBox").innerHTML= galleryarray[curimg];
}
window.onload=function(){
setInterval("rotateimages()", 3700)
}
</script>
</head>
<div style="width: 500px;">
<img id="slideshow" src="images/slideshow2/image1.jpg"/ width=500>
</div>
<div style="
-webkit-transform: rotate(-90deg); -moz-transform: rotate(-90deg); -moz-transform-origin: bottom left; filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=2);"
id=CaptionBox class=Caption>
<a> This is the default caption.
</a> </div>
VERY CURIOUS :D
best Sam