开发者

php slideshow sample

I try to do a simple image slideshow in php (just cycle images, no links, no other effects).

开发者_如何学编程

after some googling I found the following in net:

<HTML>
<HEAD>
<TITLE>Php Slideshow</TITLE>
<script language="javascript">
var speed = 4000; // time picture is displayed
var delay = 3; // time it takes to blend to the next picture
x = new Array;
var y = 0;

<?php
$tel=0;
$tst='.jpg';
$p= "./images";
$d = dir($p);
$first = NULL;
while (false !== ($entry = $d->read())) {
    if (stristr ($entry, $tst)) {
        $entry = $d->path."/".$entry; 
        print ("x[$tel]='$entry';\n");
        if ($first == NULL) { 
            $first = $entry; 
        }
        $tel++;
    }
}
$d->close();
?>

function show() {
    document.all.pic.filters.blendTrans.Apply();
    document.all.pic.src = x[y++];
    document.all.pic.filters.blendTrans.Play(delay);
    if (y > x.length - 1) 
        y = 0;
}

function timeF() {
  setTimeout(show, speed);
}
</script>
</HEAD>
<BODY >

<!-- add html code here -->
<?php
print ("<IMG src='$first' id='pic' onload='timeF()' style='filter:blendTrans()' >");
?>
<!-- add html code here -->
</BODY>
</HTML>

but it displays only the first image from the cycle. Do I something wrong?

the resulting HTML page is:

<HTML>
<HEAD>
<TITLE>Php Slideshow</TITLE>
<script language="javascript">
var speed = 4000; // time picture is displayed
var delay = 3; // time it takes to blend to the next picture
x = new Array;
var y = 0;

x[0]='./images/under_construction.jpg';
x[1]='./images/BuildingBanner.jpg';
x[2]='./images/littleLift.jpg';
x[3]='./images/msfp_smbus1_01.jpg';
x[4]='./images/escalator.jpg';

function show() {
    document.all.pic.filters.blendTrans.Apply();
    document.all.pic.src = x[y++];
    document.all.pic.filters.blendTrans.Play(delay);
    if (y > x.length - 1) 
        y = 0;
}

function timeF() {
  setTimeout(show, speed);
}
</script>
</HEAD>
<BODY >

<!-- add html code here -->
<IMG src='./images/under_construction.jpg' id='pic' onload='timeF()' style='filter:blendTrans()' ><!-- add html code here -->
</BODY>
</HTML>


I recommend you to use a ready made javascript framework, such as jQuery

As I remember, I used this: jQuery Cycle Plugin


I'm working on a jquery based slideshow plugin. You can add more images to the slideshow as the slideshow progresses.. it is in beta version.

http://smg-solutions.com

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜