Search code examples
jqueryjquery-mobileoverflowjquery-mobile-navbarjquery-mobile-table

Adaptive vertical scrollbar for jQuery Mobile tab content when navbar is in header


In some jQuery mobile tabs I have content that requires a scrollbar.

The navbar that controls them is in the header like in this fiddle.

I have tried to set height: 100%; overflow: auto; on all levels of the tab content, but the scrollbar is still applied to the page as a whole.

How can an overflowing scrollbar be adaptively applied to tabbed content only?

jsFiddle

HTML

<div data-role="page" id="mainPage">
    <div data-role="tabs" id="tabs">
        <div data-role="header" style="overflow:hidden;">
            <h1>I'm a header</h1>
            <a href="#" data-icon="gear" class="ui-btn-right">Options</a>
            <div data-role="navbar">
                <ul>
                    <li><a href="#one" class="ui-btn-active">One</a></li>
                    <li><a href="#two">Two</a></li>
                    <li><a href="#">Three</a></li>
                </ul>
            </div>
        </div>
        <div id="one" class="ui-body-d ui-content tabContent">
            <h1>First tab contents</h1>
        </div>
        <div id="two">
            <ul data-role="listview" data-inset="true">
                <li><a href="#">Acura</a></li>
                <li><a href="#">Audi</a></li>
                <li><a href="#">BMW</a></li>
                <li><a href="#">Cadillac</a></li>
                <li><a href="#">Ferrari</a></li>
            </ul>
        </div>
    </div>
</div>

JS

$(document).ready(function() {
    var $one = $('#one')
    for(var i=0; i<1000; i++){
        $one.append('<br/>content')
    }

})

CSS

body{
    overflow:hidden;
}
.tabContent{
    height:100%;
    overflow:auto;
}

Solution

  • do you need something like this? http://jsfiddle.net/VjYq9/3/

    #one{
        height:330px;
        overflow-y:scroll;
    }
    

    UPDATE: there you go http://jsfiddle.net/VjYq9/5/

    $one.height($(window).height()-120); //note that -120 must be the size of the header, so it is the window size minus the size of the header so "#one" would fit the screen!