0

我正在创建一个移动网络应用程序(非本机),我想为我的应用程序使用完整的屏幕高度。问题是浏览器的地址栏占了很大的空间,给我留下了整个屏幕的4/5左右。

我已经制作了我的应用程序,因此永远不会有任何滚动,该网站始终适合用户屏幕的高度。我真正追求的是 facebook 移动网站的功能。它向下滚动以隐藏地址栏。

对于 Android 设备和 Iphone 以及不同的移动浏览器(不同的地址栏大小),是否有任何通用的方法?

顺便说一句:我正在使用 Iscroll4 来获取固定的页脚和页眉。

编辑:这是我最终得到的代码。我添加了两个按钮让用户选择是否使用全屏模式。此代码与 Iscroll4 和 Jquery 结合使用。

<script type="text/javascript">
$(document).ready(function() {
    var fullscreen = false;

    if(fullscreen==false)
    {
        window.removeEventListener("orientationchange", function(){ hideAddressBar(); } );
        window.addEventListener("orientationchange", function(){ showAddressBar(); } );
    }
    else
    {
        window.removeEventListener("orientationchange", function(){ showAddressBar(); } );
        window.addEventListener("orientationchange", function(){ hideAddressBar(); } );
    }

    $('#fullscreen').click(function(){
       hideAddressBar();
       fullscreen = true;
    });
    $('#normalscreen').click(function(){
       showAddressBar();
       fullscreen = false;
    });

});
function hideAddressBar()
{
    document.body.style.height = (window.outerHeight + 20) + 'px';
    window.scrollTo(0, 1);
}
function showAddressBar()
{
    document.body.style.height = (window.outerHeight - 20) + 'px';
    window.scrollTo(0, 0);
}

4

4 回答 4

2

“向下滚动” javascript 技巧应该适用于 iPhone 和 Android:

http://mobile.tutsplus.com/tutorials/mobile-web-apps/remove-address-bar/

虽然很抱歉,但不确定其他移动浏览器。您是在谈论黑莓、Windows phone 等还是更基本的手机?

于 2012-05-08T10:43:09.237 回答
2

你可以在这里找到一篇关于如何实现这一点的好文章http://mobile.tutsplus.com/tutorials/mobile-web-apps/remove-address-bar/

示例脚本

function hideAddressBar()
{
  if(!window.location.hash)
  {
      if(document.height < window.outerHeight)
      {
          document.body.style.height = (window.outerHeight + 50) + 'px';
      }

      setTimeout( function(){ window.scrollTo(0, 1); }, 50 );
  }
}

window.addEventListener("load", function(){ if(!window.pageYOffset){ hideAddressBar(); } } );
window.addEventListener("orientationchange", hideAddressBar );
于 2012-05-08T10:44:13.740 回答
1

我通常这样做的方式是:

window.addEventListener("load",function() {
  setTimeout(function(){
    window.scrollTo(0, 1);
  }, 0);
});

但它只有在页面足够长以向下滚动一点时才会起作用。

于 2012-05-08T10:41:54.973 回答
0

试试这个,

对于安卓:

if(navigator.userAgent.match(/Android/i)){
    window.scrollTo(0,1);
 }

对于 iPhone:

<meta name="apple-mobile-web-app-capable" content="yes" />
于 2012-05-08T10:43:22.917 回答