<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>jQuery 3D Infinite Carousel</title>
<script type="text/javascript" src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.js'></script>
<style type="text/css" media="screen">
body {
width:100%;
height:100%;
background: #1a1a1a;
text-align: center;
margin: 0;
padding: 0;
}
.carousel {
display:none;
width: 505px;
position: relative;
overflow: hidden;
margin: 0;
height: 300px;
float:left;
left:50px
}
.carousel img {
position: absolute;
border: 3px solid #aaa;
}
.inactive {
width: 0;
left: 130px;
display: none;
}
.active {
left: 90px;
width: 320px;
z-index: 2;
display: inline-block;
cursor:pointer;
}
.right, .left {
width: 240px;
top: 30px;
z-index: 1
}
.right {
left: 260px;
}
.left {
left: 0px;
}
.button {
cursor: pointer;
width: 48px;
height: 48px;
position: absolute;
float: left;
top: 85px;
}
#left {
background: url(http://cdn.iconfinder.net/data/icons/oxygen/48x48/actions/go-next-rtl.png) no-repeat
}
#right {
background: url(http://cdn.iconfinder.net/data/icons/oxygen/48x48/actions/go-previous-rtl.png) no-repeat;
right: 0
}
#carousel_wrapper {
position: relative;
height: 220px;
width: 605px;
margin: 100px auto;
}
</style>
</head>
<body>
<div class='carousel'>
<img src='http://l.yimg.com/g/images/home_photo_visualpanic.jpg' alt="" />
<img src='http://l.yimg.com/g/images/home_photo_rappensuncle.jpg' alt="" />
<img src='http://l.yimg.com/g/images/home_photo_lyn.jpg' alt="" />
<img src='http://l.yimg.com/g/images/home_photo_aussiegall.jpg' alt="" />
<img src='http://l.yimg.com/g/images/home_photo_ende.jpg' alt="" />
<img src='http://l.yimg.com/g/images/home_photo_notsogoodphotography.jpg' alt="" />
<img src='http://l.yimg.com/g/images/home_photo_kk.jpg' alt="" />
<img src='http://l.yimg.com/g/images/home_photo_megansoh.jpg' alt="" />
<img src='http://l.yimg.com/g/images/home_photo_codepoet.jpg' alt="" />
</div>
</body>
</html>
$(function() {
$('.carousel').carousel();
});
(function($) {
$.fn.carousel = function() {
$carousel = $(this);
$carousel.wrap('<div id="carousel_wrapper"></div>');
$carousel.parent().append('<div class="button" id="left"></div>'+
'<div class="button" id="right"></div>');
$('img',this).attr('class', 'inactive');
$('img:eq(1)',this).attr('class', 'left');
$('img:eq(2)',this).attr('class', 'active');
$('img:eq(3)',this).attr('class', 'right');
$carousel.fadeIn(500);
$('.button').live('click', function(e) {
e.preventDefault();
var mode = this.id;
var $button = $('.' + mode );
$button.css({
'z-index' : 9999 ,
'opacity': 0.8
}).animate({
'left': '90px',
'width': '320px',
'top': '0px',
'opacity': 1
}, 500, function() {
$(this).attr({'class':'active','rel':'lightbox'}).removeAttr('style');
$(this).siblings().removeAttr('rel');
});
$button.prev().css({
'opacity': 0.5
}).animate({
'left': '0px',
'width': '240px',
'top': '30px',
'opacity': 1
}, 400, function() {
$(this).attr('class', 'left').removeAttr('style');
$(this).prevAll().attr('class', 'inactive');
});
$button.next().css({
'opacity': 0.5
}).animate({
'left': '260px',
'width': '240px',
'top': '30px',
'opacity': 1
}, 400, function() {
$(this).attr('class', 'right').removeAttr('style');
$(this).nextAll().attr('class', 'inactive');
});
if (mode == 'left')
$('img:last' , $carousel).prependTo($carousel);
if (mode == 'right')
$('img:first' , $carousel).appendTo($carousel);
});
}
})(jQuery);
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |