【问题标题】:android view + jquery安卓视图+jquery
【发布时间】:2013-04-01 20:03:06
【问题描述】:

我正在使用 webview GUI 开发一个 android 应用程序。我有一个包含页面的元素。它有一个页眉和一个页脚。

<div data-role="page">
  <div data-role="header">
    ...
  </div>
  <div data-role="content" id="bg_im">
    ...
  </div>
  <div data-role="footer">
    ...
  </div>
</div>

我想插入一个图像作为内容 div 的背景,这样整个内容不会占用比可用屏幕尺寸更多的空间。

我有一个 javascript 可以做到这一点:

document.getElementById("bg_im").style.height=Math.floor($(window).height() - $('#home_header').height() - $('#home_footer').height() +"px";

该函数在页面加载时执行。

它在桌面浏览器(chrome、mozilla)中运行良好,但在 android 的 webview 中加载时失败。我发现原因是页眉和页脚的函数.height() 返回的值为0。

知道为什么吗?我试过this solution,但它也不起作用。它仍然返回页眉/页脚大小 0。

【问题讨论】:

    标签: javascript android jquery html webview


    【解决方案1】:

    您的主要问题可能来自您的 Math.floor() 方法。您正在混合字符串连接和算术运算。您应该将这些语句分开。

    var newHeight = Math.floor($(window).height() - $('#home_header').height() - $('#home_footer').height()); 
    $('#bg_img').prop('height', newHeight);
    

    【讨论】:

    • 我不认为这是问题所在。它确实返回一个数字,在这种情况下等于 $(window).height()。另外,如果我打印出 $('#home_header').height(),它会打印一个 0。对于 footer.so 问题是它不会减去页眉和页脚的大小,因为这两个数字都是 0,我可以'不知道为什么。
    • 你是在 $(document).ready({}); 中调用这些方法吗?功能(api.jquery.com/ready)?如果文档尚未准备好,则 div 高度可能为零。你也可以检查这个问题stackoverflow.com/questions/9095967/…
    • 是的,函数调用方式如下:$(document).ready(function(){ resizeContent(); $(window).resize(function() { resizeContent(); } ); });
    猜你喜欢
    • 2011-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-22
    相关资源
    最近更新 更多