简体   繁体   English

mobileSafari:重新加载后自动滚动/平移到页面上的特定位置

[英]mobileSafari: Auto Scroll/Pan to specific position on page after reload

I'm programming a Webpage/-Application for the iPhone. 我正在为iPhone编写网页/应用程序。 I need to scroll to a specific position after page reload, no matter where I scrolled to while using the page before. 重新加载页面后,无论我以前使用页面时滚动到什么位置,我都需要滚动到特定位置。 The script I use works fine in firefox but not in mobileSafari. 我使用的脚本在Firefox中可以正常工作,但在mobileSafari中却不能。 In contrast to firefox, mobileSafari seems to save the position I scrolled to previously and jumps there after reload, ignoring my scrollTo triggered on reload. 与Firefox相比,mobileSafari似乎保存了我以前滚动到的位置,并在重新加载后跳转到该位置,而忽略了重新加载时触发的scrollTo。

This is the code I use: 这是我使用的代码:

function scroller(){scrollTo(1000,1000);}
window.addEventListener("load",scroller, false);

It works with click-events that I trigger manually. 它适用于我手动触发的点击事件。 If I click a button to trigger the scroll function than the scrolling is done. 如果单击按钮触发滚动功能,则滚动完成。 I tried to trigger the click via a synthetic event javascript, but this does not work either. 我试图通过合成事件JavaScript触发点击,但这也不起作用。

Is there any way the scrolling can be archived on reload and/or other not explicitly user triggered events? 有什么方法可以在重新加载和/或其他未明确用户触发的事件中存档滚动?

I did not find a solution for the actual problem which seems to be a bug. 我没有找到解决实际问题的方法,这似乎是一个错误。 But I found a workaround. 但是我找到了解决方法。 This is not to trigger the scrolling directly via an onload event but to use a setTimeout() 这不是通过onload事件直接触发滚动,而是使用setTimeout()

init(){
setTimeout(scrollTo(0, 1000), 10)
//more code
}
//more code
window.onload=init;

iscroll原型呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM