cyb*_*rld 14 html javascript uiwebview ipad ios
我在我的iPad程序中加载了带有html的UIWebView.通过使用-webkit-column-width,我将html分成几列.
padding: 0px
height: 1024px
-webkit-column-gap: 0px
-webkit-column-width: 768px
Run Code Online (Sandbox Code Playgroud)
如何在webview中获取元素位置(x,y)?位置在屏幕位置,而不是在html中.因此y的范围从0到webview的高度.
提前致谢.
Joh*_*ool 34
因为必须包含jQuery只是为了这个糟透了:
- (CGRect)positionOfElementWithId:(NSString *)elementID {
NSString *js = @"function f(){ var r = document.getElementById('%@').getBoundingClientRect(); return '{{'+r.left+','+r.top+'},{'+r.width+','+r.height+'}}'; } f();";
NSString *result = [self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:js, elementID]];
CGRect rect = CGRectFromString(result);
return rect;
}
Run Code Online (Sandbox Code Playgroud)
好的,我使用 jquery 函数解决了
var p = $("tag");
var position = p.position();
Run Code Online (Sandbox Code Playgroud)
我得到真实的 x、y 值。谢谢。
| 归档时间: |
|
| 查看次数: |
6480 次 |
| 最近记录: |