jqueryで簡単スライドショーを作ってしまえました。

HTMLはこれ。

<div id="slideshow">
    <img src="img/img1.jpg" alt="" />
    <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;
}

で、以下をhead内に埋め込む。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></script>
       <script type="text/javascript">
          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()", 4000 );
          });
       </script> 
 

こちらが元記事。↓ サンプルスライドショーもあります。
http://jonraasch.com/blog/a-simple-jquery-slideshow

jqueryのソースはDLして自分のサイトにUpして使ったほうがいいでしょう。
http://findaway-i.jp/dl/jquery-1.2.6.min.js

本当は、写真ごとにリンク先を変えたりしたかったけど、うまくできなかったのでリンクは断念しました。


Write a comment