开发者

Design Strategy - Large HTML in apps bookmark location

I write Windows/iPhone/Android apps that mostly display large documents (HTML) in an HTML container view.

What is a good strategy to determine where in a document the users has scrolled to so that when the app runs again, it goes to that location in the HTML document?

All of my software can 'listen'开发者_开发问答 to javascript.

Is there a way to find in a HTML page, perhaps with javascript, where the visible section is?

Ian


The following code works to get the scrolled position:

var ScrollTop = document.body.scrollTop;

if (ScrollTop == 0)
{
    if (window.pageYOffset)
        ScrollTop = window.pageYOffset;
    else
        ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
}

To find the viewable region also consider the dimensions of the viewport.

If you have use of jQuery, you may bind a handler to the scroll event.

For simple (not dynamically generated) pages, most web browsers will return the user to the scrolled position automatically. Be aware that if it is done in javascript, there may be a flash of the top of the page before your code executes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜