强制 data-role="page"无论方向如何,始终保持 100% 高度

发布于 2024-12-28 09:59:34 字数 207 浏览 0 评论 0 原文

我尝试在 CSS 和 jquery 上解决这个问题,但一切都失败了。是否有默认方法始终保持数据角色页面或内容以 100% 高度显示?

每次我使用纵向模式并且 data-role="content" 内的内容很短时,都会留下令人讨厌的空白。请参阅附件中的截图。

请帮忙

I tried working on this on CSS and jquery but everything fails. Is there a default way to ALWAYS keep the data-role page or content to display in 100% HEIGHT?

Every single time i do a portrait mode and the content inside the data-role="content" is short, it leaves a nasty white space. please see capture attached.

Please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

盛夏已如深秋| 2025-01-04 09:59:34
<div data-role="header" data-position="fixed"></div>
<div data-role="content">
   Content Goes here            
</div>
<div data-role="footer" data-position="fixed" ></div>

data-position="fixed" 将始终使页眉和页脚粘在屏幕的顶部和底部,内容将被重命名区域占用

<div data-role="header" data-position="fixed"></div>
<div data-role="content">
   Content Goes here            
</div>
<div data-role="footer" data-position="fixed" ></div>

data-position="fixed" will always make the header and footer stick to top and bottom of the screen and content will be occupied by the renaming area

孤君无依 2025-01-04 09:59:34

您可以使用 jQueryMobile 计算出视口的高度,然后去掉页眉和页脚 div 的高度。剩下的就是您需要的高度。

HTML - 每个页面

<body onload="init()">
    <div data-role="page" id="page" data-theme="a">
        <div data-role="header">
            <h1>Header text</h1>
        </div>
        <div class="page-content">
            <div data-role="content">
                <h1>Content here...</h1>
            </div>
            <div data-role="content">
                <h1>More content here...</h1>
            </div>
        </div>
        <div data-role="footer">
            <h4>Footer text</h4>
        </div>
    </div>
</body>

JS

// Function called when page has loaded
function init() {
  document.addEventListener("deviceready",onDeviceReady,false);
}

// Function called when phonegap is ready
function onDeviceReady() {
    //All pages at least 100% of viewport height
    var viewPortHeight = $(window).height();
    var headerHeight = $('div[data-role="header"]').height();
    var footerHeight = $('div[data-role="footer"]').height();
    var contentHeight = viewPortHeight - headerHeight - footerHeight;

    // Set all pages with class="page-content" to be at least contentHeight
    $('div[class="page-content"]').css({'min-height': contentHeight + 'px'});
 }

You can use jQueryMobile to work out the height of the viewport, then take away the header and footer div heights. You are left with the height you require.

HTML - for each page

<body onload="init()">
    <div data-role="page" id="page" data-theme="a">
        <div data-role="header">
            <h1>Header text</h1>
        </div>
        <div class="page-content">
            <div data-role="content">
                <h1>Content here...</h1>
            </div>
            <div data-role="content">
                <h1>More content here...</h1>
            </div>
        </div>
        <div data-role="footer">
            <h4>Footer text</h4>
        </div>
    </div>
</body>

JS

// Function called when page has loaded
function init() {
  document.addEventListener("deviceready",onDeviceReady,false);
}

// Function called when phonegap is ready
function onDeviceReady() {
    //All pages at least 100% of viewport height
    var viewPortHeight = $(window).height();
    var headerHeight = $('div[data-role="header"]').height();
    var footerHeight = $('div[data-role="footer"]').height();
    var contentHeight = viewPortHeight - headerHeight - footerHeight;

    // Set all pages with class="page-content" to be at least contentHeight
    $('div[class="page-content"]').css({'min-height': contentHeight + 'px'});
 }
君勿笑 2025-01-04 09:59:34

尝试将背景图像附加到 body 或 html 元素。

Try to append the backgoround image to the body or html element.

蔚蓝源自深海 2025-01-04 09:59:34

我认为问题是您的页面使用默认数据主题,或者您正在使用 data-theme =“c”。尝试使用:

Use data-theme="a" on your page

I think the issue is your page is with either default data theme or you are using data-theme = "c". Try using:

Use data-theme="a" on your page
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文