jquery - Specifying the styles for the selected tab in a navbar -
jquery - Specifying the styles for the selected tab in a navbar -
i have next html code
<!doctype html> <html lang="en"> <head> <meta name="viewport" content="width=device-width; initial-scale=1.0" /> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.css" /> <script src="http://code.jquery.com/jquery-1.6.1.min.js"></script> <script src="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js"></script> </head> <body> <div data-role="page" id="home"> <div data-role="header" data-theme="b"> <h1>test</h1> </div> <div data-role="content" data-theme="d"> <div data-role="navbar" data-theme="d"> <ul> <li><a href="#" data-icon="custom" class="ui-btn-active">home</a></li> <li><a href="#" data-icon="grid">second page</a></li> <li><a href="#" data-icon="star">third page</a></li> </ul> </div> </div> </div> </body> </html> what want accomplish set styles active tab in navbar , alter icon , background selected tab(icon different different tabs).
using css can target active tab
.ui-btn-active{ background:red !important; } but want target each tabs separately because need separate selected icons each tab(or lets say,for ease of illustration purpose-i need different active tab color each tab:red first,blue second,green third)
you can see here - http://jsfiddle.net/8pwfk/
please allow me know how accomplish this.thanks in advance
edit:the real challenge facing setting selected state custom icon.this css utilize custom icon:
.tab1 .ui-icon { background: url(icon1.png) 50% 50% no-repeat; background-size: 30px 30px; } i think need somehow connect .ui-btn-active , .ui-icon work.but not able figure out how.
add id each element want style css:
live example:
http://jsfiddle.net/phillpafford/8pwfk/4/html:
<li><a href="#" data-icon="custom" class="ui-btn-active" id="custom-li-1">home</a></li> <li><a href="#" data-icon="grid" id="custom-li-2">second page</a></li> <li><a href="#" data-icon="star" id="custom-li-3">third page</a></li> css:
#custom-li-1.ui-btn-active { background:green !important; } #custom-li-2.ui-btn-active { background:red !important; } #custom-li-3.ui-btn-active { background:blue !important; } docs custom icons:
http://jquerymobile.com/demos/1.0b1/docs/buttons/buttons-icons.html http://jquerymobile.com/demos/1.0b1/docs/toolbars/docs-navbar.htmlcustom icons
to utilize custom icons, specify data-icon value has unique name myapp-email , button plugin generate class prefixing ui-icon- data-icon value , apply button. can write css rule targets ui-icon-myapp-email class specify icon background source. maintain visual consistency, create white icon 18x18 pixels saved png-8 alpha transparency.
and
using 3rd party icon sets
you can add together of popular icon libraries glyphish accomplish ios style tab tab has big icons stacked on top of text labels. required bit of custom styles link icons , position them in navbar. here illustration using glyphish icons , custom styles (view page source styles) in our navbar:
related links:
a bottom navbar in jquery mobile looking iphone navbar, possible? http://jsfiddle.net/vh4ca/62/update:
here think you're looking for:
http://jsfiddle.net/phillpafford/8pwfk/29/js:
$('#custom-li-1').click(function() { $(this).attr('data-icon','star'); $(this).children().children().next().removeclass('ui-icon-custom').addclass('ui-icon-star'); }).page(); $('#custom-li-2').click(function() { $(this).attr('data-icon','home'); $(this).children().children().next().removeclass('ui-icon-grid').addclass('ui-icon-home'); }).page(); $('#custom-li-3').click(function() { $(this).attr('data-icon','grid'); $(this).children().children().next().removeclass('ui-icon-star').addclass('ui-icon-grid'); }).page(); jquery html5 css3 jquery-mobile
Comments
Post a Comment