2012年2月28日火曜日

シンプルでアニメーションの時間も設定できるjQueryスライドショープラグイン

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

<style type="text/css"> 
<!--    
#slideshow {
    position:relative;
}
#slideshow img {
    position:absolute;
    top:0;
    left:0;
    z-index:8;
}
#slideshow img.active {
    z-index:10;
}
#slideshow img.last-active {
    z-index:9;
}
--> 
</style>


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

0 件のコメント: