Get the div of the current scroll offset of the UIWebView

I have two different HTML files, two different UIWebViewsand UISegmentControl. On segmentChangedI displayed WebViewby uploading an HTML file. Both HTML files contain common sections, only the contents of the section are changed. Now I want to implement a functionality that, when a user reads the section 1.1first WebViewand clicks Segmentto download the second WebView, then the second WebViewmust scrollbefore section 1.1, which he reads in the first WebViewand vice versa. There are also n rooms. I used the following javacript, but it needs the current parameter div id. But on scroll, how can I get the current visible div id. I gave idfor everyone div.

function pointInView(id)
{
    var divid = document.getElementById(id);
    divid.scrollIntoView(true);
    return false;
}

Someone please help me.

+5
source share
4 answers

I searched a lot to get the div id from the current one scroll offset, but didn't get a solution for it. So I'm moving on to another option that stores the start and end offsets of each section in both files. Therefore, I created one lookup table in the database and saved the start and end offsets of each section in both files.

ex. When the user is the scrollsfirst webviewbefore section 1.1and presses the switch to open the second webview, then I am the scrolledsecond webviewin section 1.1 in the second file.

+2
source

I think jquery might come to your aid.

Could you use jQuery since it is cross-browser compatible?

http://stackoverflow.com/questions/5353934/check-if-element-is-visible-on-screen

Check BenM answer form

+2

db. click -

$('.action').click(function(){
    document.location = yourSecondFIleLocation+'?offset = ' + $('selectorDiv').detOffsetFromParentDiv(); //or get the scroll offset from the page.
});

php jQuery, .

, , .

+1

, ,

. , :

  • , -, - , CGFloat offset = webView1.scrollView.contentOffset.y; , -, -.

  • Set webView1.scrollView.contentOffset = webView2.scrollView.contentOffset   

, .

0

All Articles