More than 5 items per line in jQuery Mobile navbar

前端 未结 8 1260
青春惊慌失措
青春惊慌失措 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:13

    After:

    /* grid d: 20/20/20/20/20 */ .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 { width: 19.925%; } .ui-grid-d > :nth-child(n) { width: 20%; } .ui-grid-d .ui-block-a { clear: left; }

    in CSS, ADD

    /* 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.66%; } .ui-grid-e > :nth-child(n) { width: 16.6%; } .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.28%; } .ui-grid-f > :nth-child(n) { width: 14.28%; } .ui-grid-f .ui-block-a { clear: left; }

    And do a little modification in js:

    (function( $, undefined ) {
    $.fn.grid = function( options ) {
        return this.each(function() {
    
            var $this = $( this ),
                o = $.extend({
                    grid: null
                }, options ),
                $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";
                        $this.addClass( "ui-grid-duo" );
                    }
                }
                iterator = gridCols[grid];
                //alert(iterator);
    
            $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(" + iterator + "n+3)" ).addClass( "ui-block-c" );
            }
            if ( iterator > 3 ) {
                $kids.filter( ":nth-child(" + iterator + "n+4)" ).addClass( "ui-block-d" );
            }
            if ( iterator > 4 ) {
                $kids.filter( ":nth-child(" + iterator + "n+5)" ).addClass( "ui-block-e" );
            }
            if ( iterator > 5 ) {
                $kids.filter( ":nth-child(" + iterator + "n+6)" ).addClass( "ui-block-f" );
            }
            if ( iterator > 6 ) {
                $kids.filter( ":nth-child(" + iterator + "n+7)" ).addClass( "ui-block-g" );
            }
        });
    };
    })( jQuery );
    

    You can use up to 7 grid by this. In html code use data-grid="e" for 6 grid, data-grid="f" for 7 grid.

提交回复
热议问题