Search code examples
jquerymobilescrollbarpanelsidebar

Two scrollbars in Jquery mobile panel?


Is there a way to eliminate the second scrollbar that appears when opening the panel on my page? This problem appears when the panel's contents extend the height of the viewport.

Ideally, I would be able to use the page's original scrollbar to navigate the panel, without scrolling the content of the page. Much like the REI webiste in responsive mode.

Here's my fiddle.

CSS:

.ui-panel .ui-panel-inner {
    overflow: auto;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0px;  
    -webkit-overflow-scrolling: touch;
}

HTML:

<div data-role="page">
    <div data-role="panel" id="sidebar" data-position="right" data-display="push">
    <a href="#" data-rel="close">Close panel</a>
 <p> 1995<br>1996<br>1997<br>1998<br>2000<br>2001<br>2002<br>2003<br>2004<br>2005<br>2006<br>2007<br>2008<br>2009<br>2010<br>2011<br>2012<br>2013<br>2014<br>2015<br>2016<br>2017</p>
    </div>
    <div><a  href="#sidebar">Menu</a>
    </div>
    
    <div data-role="content">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
        
        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </div>
</div>

Solution

  • I found a way to do this using a bit of jquery code (no need for the jquerymobile anymore). Once the menu button is clicked to open the side panel, an html class is added to the content of the page that makes it 100vh and overflow:hidden, while the sidebar is in a fixed position and scrolling.

    Here's the fiddle.

    New Code:

    $('#open').click(function(){
    if($('#B').width() > 0){
    $('#B').animate({width: '0px'}),
    $( ".container" ).removeClass( "no-scroll" ).animate({right: '200px'});
    }
    else{
    $('#B').animate({width: '200px'}),
    $( ".container" ).addClass( "no-scroll" ).animate({right: '200px'});
    }
    });
    
    $('#close').click(function(){
    $('#B').animate({width:"0px"}),
    $( ".container" ).removeClass( "no-scroll" ).animate({right: '0px'});
    });
    
    
    .no-scroll{
      height:100vh !important;
      overflow: hidden !important;
    }
    

    I'm not sure if it's the most elegant solution, but it's working as desired in Firefox and Chrome.