Carousel

HTML

<div class="carousel-wrapper">    
<ul class="carousel">
    <li class="item">
        <p>hey</p>
    </li>
    <li class="item">
        <p>hey</p>
    </li>
    <li class="item">
        <p>hey</p>
    </li>
    <li class="item">
        <p>hey</p>
    </li>
</ul>
<div class="carousel-nav">
    <a href="" class="prev">&lt;</a>
    <a href="" class="next">&gt;</a>   
</div>
</div>

CSS

@import url(http://fonts.googleapis.com/css?family=Open+Sans:300,400);
.container {
    font-family: 'Open Sans', sans-serif;
    font-size: 14px;
    font-weight: 300;
    width: 800px;
    margin: 10px auto;
}

.container h1 {
    color: #ccc;
    font-size: 32px;
    font-weight: 800;
    margin-bottom: 20px;
    text-shadow: 1px 1px 0 #999;
}

.container p {
    margin: 5px 0;
}

.carousel-wrapper {
    position: relative;
    width: 800px;
    height: 240px;
    overflow: hidden;
    border-top: 1px dotted #ccc;
    border-bottom: 1px dotted #ccc;
    margin: 20px 0;
}

.carousel {
    position: absolute;
}

.carousel li {
    display: block;
    float: left;
    width: 800px;
    height: 240px;
    position: relative;
}

.carousel img {
    position: absolute;
    z-index: 0;
}

.carousel p.text {
    position: absolute;
    z-index: 1;
    font-size: 24px;
    width: 340px;
    right: 80px;
    top: 10px;
    color: #ff6347;
    background-color: #111111;
    background-color: rgba(0,0,0,0.7);
    padding: 5px;
}

.carousel-nav a {
    display: block;
    height: 40px;
    width: 30px;
    font-size: 24px;
    line-height: 1.6;
    font-weight: 800;
    color: #222;
    background-color: rgb(255,99,71);
    background-color: rgba(255,99,71,0.7);
    text-decoration: none;
    padding: 0 4px;
    position: absolute;
    top: 50%;
    margin-top: -20px;
    text-align: center;
    z-index: 10;
}

.carousel-nav a.prev {
    left: 0;
    -webkit-border-top-right-radius: 4px;
    -webkit-border-bottom-right-radius: 4px;
    -moz-border-radius-topright: 4px;
    -moz-border-radius-bottomright: 4px;
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
}

.carousel-nav a.next {
    right: 0;
    -webkit-border-top-left-radius: 4px;
    -webkit-border-bottom-left-radius: 4px;
    -moz-border-radius-topleft: 4px;
    -moz-border-radius-bottomleft: 4px;
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
}

JavaScript

(function() {
    var first = $('.item').first(),
        last = $('.item').last(),
        itemWidth = first.width(),
        carousel = $('.carousel');
    carousel.prepend(last.clone()).append(first.clone());
    carousel.width(itemWidth * $('.item').length);
    carousel.css({left: -itemWidth});
    $('.prev').on('click', function(e){
        e.preventDefault();
        carousel.animate({left: '+=' + itemWidth}, 300, function(){
            if(Math.abs(carousel.position().left) < 2) {
                carousel.css({left: -itemWidth * (carousel.children().length - 2)});
            }
        });
        return false;       
    });
    $('.next').on('click', function(e){
        e.preventDefault();
        carousel.animate({left: '-=' + itemWidth}, 300, function(){
            if(Math.abs(carousel.position().left + itemWidth * (carousel.children().length - 1)) < 2) {
                carousel.css({left: -itemWidth});
            }
        });
        return false;       
    });
})();