I have an SVG file displayed inside UIWebView. This SVG contains several tags <a>that indicate tangible elements. After loading the SVG file, I would like to scroll the view so that a certain element is somewhere near the center of the screen.
What I have so far looks something like this:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[diagramView stringByEvaluatingJavaScriptFromString:@""
"var e = document.getElementById('myelement');"
"var top = e.offsetTop;"
"while (e.offsetParent) {"
" e = e.offsetParent;"
" top += e.offsetTop;"
"}"
"alert(top);"
//"scrollTo(0, top);"
];
}
However top, 0 ends when this is done. The element epoints to the correct <a>element of the SVG file (marked with alert(e.id)). I cannot find the correct combination of element attributes that gives me the actual offset.
I could hardcode the suitable set of offsets, but I really don't want that.