<html>
<head>
<script class="jsbin" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
div.slide { padding:20px; color: #fff; background: red; width:400px; height:400px; }
#status { float:right; width: 100px; background:#444; color:#fff; padding:10px; border:1px solid #999;}
</style>
</head>
<body>
<div id="status"></div>
<div class="slide">
<h1>Slide One</h1>
</div>
<div class="slide">
<h1>Slide Two</h1>
</div>
<div class="slide">
<h1>Slide Three</h1>
</div>
<div class="slide">
<h1>Slide Four</h1>
</div>
</body>
</html>
//wrap the whole plugin in a closure
(function($){
//create a jQuery collection method
$.fn.clickthrough = function(options){
//private vars
var number_of_slides = this.length,
slides = this,
settings = $.extend({
'bg_color' : 'red',
'text_color' : 'white'
}, options); // we have set some defaults and merged them with the incoming 'options' object
return this.each(function(i, slide){
var next_slide = (i + 1 < number_of_slides) ? i + 1 : 0;
if(i > 0)
$(slide).hide();
$(slide).bind('click', function(){
$(this).fadeOut('slow', function(){
$(slides.eq(next_slide))
.show()
.trigger('slideOpen', (next_slide + 1)); //custom event trigger which passes the opened slide index + 1 to offset zero indexing
});
})
.css('background', settings.bg_color)
.css('color', settings.text_color);
});
};
})(jQuery);
$(document).ready(function(){
$('div.slide').clickthrough({
'bg_color' : 'blue',
'text_color' : 'yellow'
}).bind('slideOpen', function(event, slide_id){
$('#status').html('slide ' + slide_id + ' open');
});
});
Output
300px
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. |