如何在 iPhone Web 应用程序中创建页脚/工具栏?
我正在开发一个网络应用程序,我需要一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这种情况在 iOS 5 中发生了变化。现在您可以使用
overflow:scroll
或position:fixed
,它会执行预期的操作。例如,这种类型的代码:...应该可以正常工作。
尽管仍有许多设备运行较旧的 iOS 版本,因此您可能希望在较旧的设备上延迟加载可滚动性 ,您可以使用以下 javascript 进行测试:
This situation has changed with iOS 5. Now you can use
overflow:scroll
orposition:fixed
and it will do what is expected. For example, this type of code:...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:
你不能。至少不是你想的那样。
你必须假装整个事情都是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.
下面是一个关于如何结合 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.
这是一个带有代码的工作示例。它不适合胆小的人:
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/
有一个新的 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!