More than 5 items per line in jQuery Mobile navbar

前端 未结 8 1263
青春惊慌失措
青春惊慌失措 2021-02-01 17:45

I have unsuccessfully looked for a variable to change the maximum number of items in a single line in a navbar.

I am just starting with jQuery Mobile, trying to create

相关标签:
8条回答
  • 2021-02-01 18:26

    From Phill Pafford

    "and add these: .... " { css code }

    please change to .... (NOTE: Width changed to 16.65%. This note added because StackOverflow doesn't allow one-letter edits.)

    /* grid e: 16/16/16/16/16/16 */
    .ui-grid-e .ui-block-a, .ui-grid-e .ui-block-b, .ui-grid-e .ui-block-c, .ui-grid-e .ui-block-d, .ui-grid-e .ui-block-e, .ui-grid-e .ui-block-f { width: 16.65%; }
    .ui-grid-e .ui-block-a { clear: left; }
    
    /* grid f: 14/14/14/14/14/14/14 */
    .ui-grid-f .ui-block-a, .ui-grid-f .ui-block-b, .ui-grid-f .ui-block-c, .ui-grid-f .ui-block-d, .ui-grid-f .ui-block-e, .ui-grid-f .ui-block-f, .ui-grid-f .ui-block-g { width: 14.2857%; }
    .ui-grid-f .ui-block-a { clear: left; }
    
    0 讨论(0)
  • 2021-02-01 18:30

    You're right jQM limits the columns to 5. Looking over the code this seems to be the function:

    /*
    * jQuery Mobile Framework : plugin for creating CSS grids
    * Copyright (c) jQuery Project
    * Dual licensed under the MIT or GPL Version 2 licenses.
    * http://jquery.org/license
    */ 
    (function($, undefined ) {
    $.fn.grid = function(options){
        return this.each(function(){
            var o = $.extend({
                grid: null
            },options);
    
    
            var $kids = $(this).children(),
                gridCols = {solo:1, a:2, b:3, c:4, d:5},
                grid = o.grid,
                iterator;
    
                if( !grid ){
                    if( $kids.length <= 5 ){
                        for(var letter in gridCols){
                            if(gridCols[letter] == $kids.length){ grid = letter; }
                        }
                    }
                    else{
                        grid = 'a';
                    }
                }
                iterator = gridCols[grid];
    
            $(this).addClass('ui-grid-' + grid);
    
            $kids.filter(':nth-child(' + iterator + 'n+1)').addClass('ui-block-a');
            if(iterator > 1){   
                $kids.filter(':nth-child(' + iterator + 'n+2)').addClass('ui-block-b');
            }   
            if(iterator > 2){   
                $kids.filter(':nth-child(3n+3)').addClass('ui-block-c');
            }   
            if(iterator > 3){   
                $kids.filter(':nth-child(4n+4)').addClass('ui-block-d');
            }   
            if(iterator > 4){   
                $kids.filter(':nth-child(5n+5)').addClass('ui-block-e');
            }
    
        }); 
    };
    

    It will take some work but you can extend this to the desired 7 column layout. You will also need to add the custom CSS as well to handle the new columns, so you new function would look something like this

    /*
    * jQuery Mobile Framework : plugin for creating CSS grids
    * Copyright (c) jQuery Project
    * Dual licensed under the MIT or GPL Version 2 licenses.
    * http://jquery.org/license
    */ 
    (function($, undefined ) {
    $.fn.grid = function(options){
        return this.each(function(){
            var o = $.extend({
                grid: null
            },options);
    
    
            var $kids = $(this).children(),
                gridCols = {solo:1, a:2, b:3, c:4, d:5, e:6, f:7},
                grid = o.grid,
                iterator;
    
                if( !grid ){
                    if( $kids.length <= 7 ){
                        for(var letter in gridCols){
                            if(gridCols[letter] == $kids.length){ grid = letter; }
                        }
                    }
                    else{
                        grid = 'a';
                    }
                }
                iterator = gridCols[grid];
    
            $(this).addClass('ui-grid-' + grid);
    
            $kids.filter(':nth-child(' + iterator + 'n+1)').addClass('ui-block-a');
            if(iterator > 1){   
                $kids.filter(':nth-child(' + iterator + 'n+2)').addClass('ui-block-b');
            }   
            if(iterator > 2){   
                $kids.filter(':nth-child(3n+3)').addClass('ui-block-c');
            }   
            if(iterator > 3){   
                $kids.filter(':nth-child(4n+4)').addClass('ui-block-d');
            }   
            if(iterator > 4){   
                $kids.filter(':nth-child(5n+5)').addClass('ui-block-e');
            }
                if(iterator > 5){   
                $kids.filter(':nth-child(6n+6)').addClass('ui-block-f');
            }
                if(iterator > 6){   
                $kids.filter(':nth-child(7n+7)').addClass('ui-block-g');
            }
    
            }); 
        };
    }); // end
    

    In the CSS:

    change this:

    .ui-block-a, .ui-block-b, .ui-block-c, .ui-block-d, .ui-block-e { margin: 0; padding: 0; border: 0; float: left; min-height:1px;}
    

    to this:

    .ui-block-a, .ui-block-b, .ui-block-c, .ui-block-d, .ui-block-e, .ui-block-f, .ui-block-g { margin: 0; padding: 0; border: 0; float: left; min-height:1px;}
    

    and add these:

    /* grid e: 16/16/16/16/16/16 */
    .ui-grid-d .ui-block-a, .ui-grid-d .ui-block-b, .ui-grid-d .ui-block-c, .ui-grid-d .ui-block-d, .ui-grid-d .ui-block-e .ui-block-f { width: 16%; }
    .ui-grid-d .ui-block-a { clear: left; }
    
    /* grid f: 14/14/14/14/14/14/14 */
    .ui-grid-d .ui-block-a, .ui-grid-d .ui-block-b, .ui-grid-d .ui-block-c, .ui-grid-d .ui-block-d, .ui-grid-d .ui-block-e .ui-block-f .ui-block-g { width: 14%; }
    .ui-grid-d .ui-block-a { clear: left; }
    

    There might be other changes as well but these are the ones that stand out as of now.

    • Link to JS
    • Link to CSS

    Failed Attempt to use buttons for the navbar but they stack on one another as well: Live Link

    0 讨论(0)
提交回复
热议问题