jQuery Mobile: Stick footer to bottom of page

后端 未结 10 866
一个人的身影
一个人的身影 2020-12-04 09:40

Is there any way, bearing in mind the way the jQuery Mobile framework operates, to fix the page so that the footer always aligns with the bottom of the page - no matter the

相关标签:
10条回答
  • 2020-12-04 10:08

    I thought I'd share my CSS only solution here. This way you can avoid the extra overhead of using JS for this.

    This isn't a fixed position footer. The footer will be offscreen if the page content is taller than the screen. I think it looks better this way.

    The body and .ui-page min-height and height are necessary to prevent the footer from jumping up and down during transitions.

    Works with the latest JQM version as of now, 1.4.0

    body,
    .ui-page {
        min-height:100% !important;
        height:auto !important;
    }
    
    .ui-content {
        margin-bottom:42px; /* HEIGHT OF YOUR FOOTER */
    }
    
    .ui-footer {
        position:absolute !important;
        width:100%;
        bottom:0;
    }
    
    0 讨论(0)
  • jQm offers:

    • http://jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/toolbars/docs-footers.html
    • http://jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/toolbars/bars-fixed.html
    • http://jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/toolbars/bars-fullscreen.html
    • http://jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/toolbars/footer-persist-a.html

    None of these work?

    0 讨论(0)
  • 2020-12-04 10:16

    In my case, I needed to use something like this to keep the footer pinned down at the bottom if there is not much content, but not floating on top of everything constantly like data-position="fixed" seems to do...

    .ui-content
    {
        margin-bottom:75px; /* Set this to whatever your footer size is... */
    }
    
    .ui-footer {
        position: absolute !important;
        bottom: 0;
        width: 100%;
    }
    
    0 讨论(0)
  • 2020-12-04 10:17

    Fixed basics

    To enable this behavior on a header or footer, add the data-position="fixed" attribute to a jQuery Mobile header or footer element.

    <div data-role="footer" data-position="fixed">
        <h1>Fixed Footer!</h1>
    </div>
    
    0 讨论(0)
  • 2020-12-04 10:19

    You can add this in your css file:

    [data-role=page]{height: 100% !important; position:relative !important;}
    [data-role=footer]{bottom:0; position:absolute !important; top: auto !important; width:100%;}  
    

    So the page data-role now have 100% height, and footer is in absolute position.

    Also Yappo have wrote an excellent plugin that you can find here: jQuery Mobile in a iScroll plugin http://yappo.github.com/projects/jquery.mobile.iscroll/livedemo.html

    hope you found the answer!

    An answer update

    You can now use the data-position="fixed" attribute to keep your footer element on the bottom.
    Docs and demos: http://view.jquerymobile.com/master/demos/toolbar-fixed/

    0 讨论(0)
  • 2020-12-04 10:19

    This script seemed to work for me...

    $(function(){
        checkWindowHeight();
        $(document).bind('orientationchange',function(event){
            checkWindowHeight();
        })
    });
    
    function checkWindowHeight(){
            $('[data-role=content]').each(function(){
            var containerHeight = parseInt($(this).css('height'));
            var windowHeight = parseInt(window.innerHeight);
            if(containerHeight+118 < windowHeight){
                var newHeight = windowHeight-118;
                $(this).css('min-height', newHeight+'px');
            }
        });
    }
    
    0 讨论(0)
提交回复
热议问题