Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change custom navbar icon on jquerymobile

Haven't found a solution for changing a custom navbar icon on a page with multiple footers.

That is what I am currently using:

    $(".live_menu .ui-icon").css("background","url(/btn_on.gif) !important");
    $(".live_menu .ui-icon").css("background-repeat","no-repeat !important");   

Any ideas?

like image 940
SteMa Avatar asked Aug 01 '11 17:08

SteMa


1 Answers

Related:

  • Specifying the styles for the selected tab in a navbar
  • A bottom navbar in jQuery mobile looking like iPhone navbar, possible?
  • http://jquerymobile.com/test/docs/buttons/buttons-icons.html

Live Example:

  • http://jsfiddle.net/phillpafford/8pwFK/29/

Custom Icons

To use custom icons, specify a data-icon value that has a unique name like myapp-email and the button plugin will generate a class by prefixing ui-icon- to the data-icon value and apply it to the button. You can then write a CSS rule that targets the ui-icon-myapp-email class to specify the icon background source. To maintain visual consistency, create a white icon 18x18 pixels saved as a PNG-8 with alpha transparency.

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();

HTML:

<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 id="custom-nav-list">
                <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>
            </ul>
        </div>
    </div>
       
</div>
like image 180
Phill Pafford Avatar answered Nov 15 '22 05:11

Phill Pafford