2010-03-07 46 views
0

我嘗試在php中做一個簡單的圖像幻燈片(只是循環圖像,沒有鏈接,沒有其他效果)。php幻燈片示例

一些谷歌上搜索後,我發現在網下:

<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> 

但是從週期只顯示第一個圖像。我有什麼問題嗎?

生成的HTML頁面:

<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> 

回答

1

我建議你使用了一個現成的JavaScript框架,比如jQuery

我記得,我用這個:jQuery Cycle Plugin

+0

你能展示一個樣本嗎?有點困惑不知道從哪裏開始。 – serhio 2010-03-07 11:47:28

+0

看到我更新的答案。 – nightcoder 2010-03-07 12:15:30

0

我m工作在基於jQuery的幻燈片插件上。幻燈片放映過程中,您可以將更多圖像添加到幻燈片中。它處於測試版。

http://smg-solutions.com