如何在 iPhone Web 应用程序中创建页脚/工具栏?

发布于 2024-08-25 12:52:52 字数 251 浏览 4 评论 0原文

我正在开发一个网络应用程序,我需要一个 div 来粘在视口的底部。始终可见并且始终位于视口的底部。这里有一个我想要的示例:页脚。不幸的是,这在 iPhone 上不起作用。我可以想出一些使用 javascript 来做到这一点的方法,但我宁愿不这样做。关于如何仅使用 CSS 在 iPhone 上获得这种效果有什么想法吗?

I'm working on a web app and I need to get a div to stick to the bottom of the viewport. Always viewable and always on the bottom of the viewport. There's an example of what I want here: footer. Unfortunately, this doesn't work on the iPhone. I can think of some ways to do this using javascript but I would rather not. Any ideas on how to get this effect on the iPhone using only css?

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

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

发布评论

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

评论(5

野生奥特曼 2024-09-01 12:52:53

这种情况在 iOS 5 中发生了变化。现在您可以使用 overflow:scrollposition:fixed ,它会执行预期的操作。例如,这种类型的代码:

<header style="
    position: fixed; top: 0; left: 0;
    width: 100%; height: 20px; font-size: 20px">
    Heading
</header>
<article style="margin: 20px 0">
    Your page here
</article>
<footer style="
    position: fixed; bottom: 0; left: 0;
    width: 100%; height: 20px; font-size: 20px">
    Footer
</footer>

...应该可以正常工作。
尽管仍有许多设备运行较旧的 iOS 版本,因此您可能希望在较旧的设备上延迟加载可滚动性 ,您可以使用以下 javascript 进行测试:

var isios = navigator.appVersion.match(/CPU( iPhone)? OS ([0-9]+)_([0-9]+)(_([0-9]+))? like/i);
// if that succeeds, it usually returns ["CPU OS X_Y_Z like",undefined,X,Y,Z]
if (isios && isios[2] < 5){
    // load scrollability here. jquery example:
    $.getScript("/js/scrollability.min.js", function() {
        // code to run when scrollability's loaded
    }
}

This situation has changed with iOS 5. Now you can use overflow:scroll or position:fixed and it will do what is expected. For example, this type of code:

<header style="
    position: fixed; top: 0; left: 0;
    width: 100%; height: 20px; font-size: 20px">
    Heading
</header>
<article style="margin: 20px 0">
    Your page here
</article>
<footer style="
    position: fixed; bottom: 0; left: 0;
    width: 100%; height: 20px; font-size: 20px">
    Footer
</footer>

...should work without problems.
Though there are still many devices running older iOS versions, so you might want to lazy-load Scrollability on older devices, which you can test with this javascript:

var isios = navigator.appVersion.match(/CPU( iPhone)? OS ([0-9]+)_([0-9]+)(_([0-9]+))? like/i);
// if that succeeds, it usually returns ["CPU OS X_Y_Z like",undefined,X,Y,Z]
if (isios && isios[2] < 5){
    // load scrollability here. jquery example:
    $.getScript("/js/scrollability.min.js", function() {
        // code to run when scrollability's loaded
    }
}
櫻之舞 2024-09-01 12:52:53

你不能。至少不是你想的那样。

你必须假装整个事情都是javascript。使用类似 iScroll 的东西,

它有点糟糕,但移动Safari 根本不支持任何类型的固定定位。因此,您必须使页面大小等于屏幕大小,然后使用 JavaScript 来处理触摸并设置滚动偏移和动画滚动条以及其他非手动操作。

我链接的这个脚本可以为您完成很多工作,但它不如本机解决方案那么强大。

You can't. At least not the way you think.

You have to fake the entire thing is javascript. Use something like iScroll

It sort of sucks but Mobile Safari does not support any kind of fixed positioning at all. So you have to make the page size equal to the screen size and then use javascript to handle touches and set scroll offsets and animate scrollbars and what not manually.

This script I linked does a lot of that for you, but it's not as robust as a native solution would be.

我是有多爱你 2024-09-01 12:52:53

下面是一个关于如何结合 CSS3、HTML 和 JavaScript 为 iPhone 创建导航栏的示例。
http://www.mindovercode.com/2010/09 /12/iphone-navbar-using-xui/

ps:它可以在横向模式下工作。

Here is an example on how to combine CSS3, HTML, and JavaScript to create a navbar for the iPhone.
http://www.mindovercode.com/2010/09/12/iphone-navbar-using-xui/

ps: It does work in landscape mode.

一个人的旅程 2024-09-01 12:52:53

这是一个带有代码的工作示例。它不适合胆小的人:

http://doctyper。 com/archives/200808/fixed-positioning-on-mobile-safari/

Here is a working example, with code. It is not for the faint of heart:

http://doctyper.com/archives/200808/fixed-positioning-on-mobile-safari/

∞觅青森が 2024-09-01 12:52:53

有一个新的 JavaScript 可以更轻松地实现此目的: http://joehewitt.github.com/scrollability/

因此在 iOS 5 中将会有固定位置和溢出滚动可用!

There is a new JavaScript for this that works much easier: http://joehewitt.github.com/scrollability/

Therefore in iOS 5 there will be fixed position and overflow scroll available!

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