Reputation: 4712
I have two different HTML files, two different UIWebViews
& a UISegmentControl
. On segmentChanged
, I had displayed the WebView
by loading a HTML file.
Both HTML files contains common sections only the section content is changed. Now I want to implement the functionality that, when user reads section 1.1
of first WebView
& clicks Segment
for loading second WebView
, then the second WebView
needs to scroll
upto the section 1.1
which he reads in first WebView
and viceversa. Also there are n number of sections.
I used following javacript but it needs the parameter of current div id
. But on scroll
, how can I get the current visible div id
. I had given the id
for each div
.
function pointInView(id)
{
var divid = document.getElementById(id);
divid.scrollIntoView(true);
return false;
}
Anyone please help me.
Upvotes: 4
Views: 1125
Reputation: 4712
I searched a lot to get the div id from current scroll offset
but didn't get the solution for it. So I go with the other option that, stored the start & end offsets of each section in both files. So I had created one look-up table in database & stored the start & end offsets of each section in both files.
ex. When user scrolls
the first webview
to section 1.1
& clicks the switch to open the second webview
, then I scrolled
the second webview
to the section 1.1 in the second file.
Upvotes: 1
Reputation: 1606
You don't really need a db entry for that. Just catch the click event via something like
$('.action').click(function(){
document.location = yourSecondFIleLocation+'?offset = ' + $('selectorDiv').detOffsetFromParentDiv(); //or get the scroll offset from the page.
});
and catch it on the second page either with php or jQuery to scroll to it.
Heck that is even achievable if you put in your code the paragraph marks and link correctly to them.
Upvotes: 1
Reputation: 1620
Please try below,
To scroll any scroll view at any position we set the content offset of the scroll view. To solve your problem we have two solutions,
In your case when user is viewing the first Web view, save the content offset of the first web view in any variable like below CGFloat offset = webView1.scrollView.contentOffset.y; Then when you open the second web view then provide this offset value to second web view scroll offset.
Set webView1.scrollView.contentOffset=webView2.scrollView.contentOffset or vice versa according to your need
I hope this will help you.
Upvotes: 0
Reputation: 631
I think jquery might be able to come to your rescue.
Could you use jQuery, since it's cross-browser compatible?
http://stackoverflow.com/questions/5353934/check-if-element-is-visible-on-screen
Check out answer form BenM
Upvotes: 2