Created
February 16, 2015 12:04
-
-
Save steve10287/c13d97fcc754c3c21a00 to your computer and use it in GitHub Desktop.
Simple Responsive Tabs with Accordion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="tab-row"> | |
<a href="#" data-tab="new-vehicles">New Vehicles</a> | |
<a href="#" data-tab="used-vehicles">Used Vehicles</a> | |
<a href="#" data-tab="new-trailers">New Trailers</a> | |
<a href="#" data-tab="used-trailers">Used Trailers</a> | |
</div> | |
<div class="tab-group"> | |
<a href="#" class="new-vehicles tab-acc" data-tab="new-vehicles">New Vehicles</a> | |
<div class="tab-content new-vehicles">New Vehicle content</div> | |
<a href="#" class="used-vehicles tab-acc" data-tab="used-vehicles">Used Vehicles</a> | |
<div class="tab-content used-vehicles">Used Vehicle content</div> | |
<a href="#" class="new-trailers tab-acc" data-tab="new-trailers">New Trailers</a> | |
<div class="tab-content new-trailers">New Trailers content</div> | |
<a href="#" class="used-trailers tab-acc" data-tab="used-trailers">Used Trailers</a> | |
<div class="tab-content used-trailers">Used Trailers content</div> | |
</div> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.tab-row { | |
display:block; | |
} | |
.tab-row a { | |
display: inline-block; | |
padding: 10px; | |
} | |
.tab-row a.active { | |
background: seagreen; | |
} | |
@media (max-width:500px){ | |
.tab-row a { | |
display:none; | |
} | |
} | |
.tab-acc { | |
display:none; | |
} | |
.tab-acc.active { | |
background: seagreen; | |
} | |
@media (max-width:500px){ | |
.tab-acc { | |
display:block; | |
} | |
} | |
.tab-content { | |
display:none; | |
} | |
.tab-content.active { | |
display:block; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.tab-row a, .tab-acc').click(function(e){ | |
var tab = $(this).data('tab'); | |
//Highlight the tab row & accordion links | |
$('.tab-row a, .tab-acc').removeClass('active'); | |
$('*[data-tab = '+tab+']').addClass('active'); | |
//Display content | |
$('.tab-content').removeClass('active') | |
$('.'+tab).addClass('active') | |
e.preventDefault() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://jsfiddle.net/aq8oc4hk/