---
title: "一个简单的jQuery Slideshow效果 (转)"
author: "zhoon"
date: "2012-04-30T17:50:02Z"
tags: []
categories: ["Web前端"]
slug: "jquery-slideshow"
draft: false
lastmod: "2012-04-30T17:51:26Z"
id: 1505795
url: "https://zhoon.iteye.com/blog/1505795"
---

下面是一个jQuery Slideshow效果，用了一种很不错的思路。请看代码：

 

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

 

```
#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;
}
```

 

 

 

```
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 );
});
```

 

大家细细品味吧。

 

原文地址：http://jonraasch.com/blog/a-simple-jquery-slideshow