Created
October 3, 2014 21:51
-
-
Save barbwiredmedia/3dd1e5099d0b79c50c1e to your computer and use it in GitHub Desktop.
Change Tabs to select box with options for mobile screens : http://jsfiddle.net/LACnj/
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
$(document).ready(function () { | |
$(window).resize(responsive); | |
$(window).trigger('resize'); | |
}); | |
function responsive () { | |
// get resolution | |
var resolution = document.documentElement.clientWidth; | |
// mobile layout | |
if (resolution < 700) { | |
if($('.select-menu').length === 0) { | |
// create select menu | |
var select = $('<select></select>'); | |
// add classes to select menu | |
select.addClass('select-menu input-block-level'); | |
// each link to option tag | |
$('.nav-tabs li a').each(function () { | |
// create element option | |
var option = $('<option></option>'); | |
// add href value to jump | |
option.val(this.href); | |
// add text | |
option.text($(this).text()); | |
// append to select menu | |
select.append(option); | |
}); | |
// add change event to select | |
select.change(function () { | |
window.location.href = this.value; | |
}); | |
// add select element to dom, hide the .nav-tabs | |
$('.nav-tabs').before(select).hide(); | |
} | |
} | |
// max width 979px | |
if (resolution > 979) { | |
$('.select-menu').remove(); | |
$('.nav-tabs').show(); | |
} | |
} |
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
<ul class="nav-tabs"> | |
<li><a href="#">Item 1</a></li> | |
<li><a href="#">Item 2</a></li> | |
<li><a href="#">Item 3</a></li> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment