I have a bunch of images being shown on click via JQuery - any easy way to animate this?

Posted by Cenk on Stack Overflow See other posts from Stack Overflow or by Cenk
Published on 2010-05-07T12:03:50Z Indexed on 2010/05/07 12:08 UTC
Read the original article Hit count: 287

This is the (quite simple) JS code I'm using:

    $(document).ready(function() {
        $(".button-list .next").click(function() {
            project = $(this).parents().filter(".projektweb").eq(0);
            currentimg = project.find(".images-list li.current");
            nextimg = currentimg.next();
            firstimg = project.find(".images-list li:first");
            currentimg.removeClass("current");
            if (nextimg.is("li")) nextimg.addClass("current");
            else firstimg.addClass("current");
            return false;
        });
        $(".button-list .prev").click(function() {
            project = $(this).parents().filter(".projektweb").eq(0);
            currentimg = project.find(".images-list li.current");
            previmg = currentimg.prev();
            lastimg = project.find(".images-list li:last");
            currentimg.removeClass("current");
            if (previmg.is("li")) previmg.addClass("current");
            else lastimg.addClass("current");
            return false;
        });
    });

And this is how the HTML code for the image list looks like:

<ul class="images-list">
    <li class="current"><img src="img/1.jpg" alt="" /></li>
    <li><img src="img/1b.jpg" alt="" /></li>
</ul>

<ul class="button-list"> <li><a class="button prev" href="#">?</a></li> 
<li><a class="button next" href="#">?</a></li></ul>

The CSS:

.images-list {
    height: 460px;
    list-style-type:none;
    float:left;
    width: 460px;
    overflow:hidden;
    position:relative;
}

.images-list img {
    height: 460px;
    width: 460px;
    display:block;
}

 .images-list li {
    display:none;
}

.images-list li.current {
    display:block;
}

What I'd like to do is animate the images as they come and go - right now they just appear, which is OK but a bit more eye-candy would be nice.

Can anyone help me out here? It it even possible to do it this way? Thanks!!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about html