2011-11-23 152 views
-2

我想要以幻燈片形式顯示圖像。我爲每張圖片都有一個鏈接和標題。圖像幻燈片腳本

當循環顯示圖像時,我也希望圖像鏈接和標題相應地改變。

我該怎麼辦?

+0

請給你的問題標籤谷歌,選擇衆多解決方案之一,然後告訴我們,如果你有與它的具體問題。 – Quasdunk

回答

1

您無法使用PHP製作幻燈片。您使用JavaScript來製作幻燈片。

退房此鏈接:

http://jquery.malsup.com/cycle/

讓我給你一個簡單的jQuery褪色幻燈片

HTML

<div id="slideshow"> 
    <img src="img/img1.jpg" alt="" class="active" /> 
    <img src="img/img2.jpg" alt="" /> 
    <img src="img/img3.jpg" alt="" /> 
</div> 

CSS

#slideshow { 
    position:relative; 
    height:350px; 
} 

#slideshow IMG { 
    position:absolute; 
    top:0; 
    left:0; 
    z-index:8; 
} 

#slideshow IMG.active { 
    z-index:10; 
} 

#slideshow IMG.last-active { 
    z-index:9; 
} 

部分JQuery

function slideSwitch() { 
    var $active = $('#slideshow IMG.active'); 

    if ($active.length == 0) $active = $('#slideshow IMG:last'); 

    var $next = $active.next().length ? $active.next() 
     : $('#slideshow IMG:first'); 

    $active.addClass('last-active'); 

    $next.css({opacity: 0.0}) 
     .addClass('active') 
     .animate({opacity: 1.0}, 1000, function() { 
      $active.removeClass('active last-active'); 
     }); 
} 

$(function() { 
    setInterval("slideSwitch()", 5000); 
}); 

哦!是的,不要忘記導入jQuery庫