Skip to content

Instantly share code, notes, and snippets.

@hsquareweb
Created November 9, 2012 18:21
Show Gist options
  • Select an option

  • Save hsquareweb/4047330 to your computer and use it in GitHub Desktop.

Select an option

Save hsquareweb/4047330 to your computer and use it in GitHub Desktop.
JavaScript: Simple Content Slider
<script type="text/javascript">
$('#tabs div').first().attr('class', 'current');
$('#tabs div').each(function(i) {
i = i + 1;
$(this).attr('id', 'tab-' + i);
if(i !== $('#tabs div').size()) {
$(this).append('<button class="tabPagination" rel="tab-' + (i + 1) + '">Next</button>');
}
if(i !== 1) {
$(this).append('<button class="tabPagination" rel="tab-' + (i - 1) + '">Previous</button>');
}
});
$('#tabs div[class!="current"]').hide();
$('.tabPagination').live('click', function() {
$('.current').removeAttr('class');
$('#tabs div[class!="current"]').hide();
$('#' + $(this).attr('rel')).show();
});
</script>
<div id="tabs">
<div>First</div>
<div>Second</div>
<div>Third</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment