Mobile jQuery in ios - how to get element position in UIWebView?
I first used jQuery-Mobile and I don't know how to use in ios my project.
Which file must i import? In http://jquerymobile.com/ site, i downloaded jquery.mobile-1.0b3.js and jquery.mobile-1.0.min.js. which i use?
This is my code.
NSString *path = [[NSBundle mainBundle] pathForResource:@"jquery.mobile-1.0b3" ofType:@"js"];
NSString *jsCode = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[self stringByEvaluatingJavaScriptFromString:jsCode];
Is this right?
And i want to get specified element. In jquery, there is a function - '.position' But mobile jquery support this function? How can i?
NSString *code = @"var p=$('p:first'); var pos=p.position()开发者_Go百科;"
NSLog(@"%@", [webView stringByEvaluatingJavaScriptFromString:@"position.left"]);
Please help me.
Thanks in advance.
I'll admit that I do not know how to use PhoneGap or UIWebView yet, but... Here is how you use jquery and jquery mobile to get the positions if it were a regular web page.
I could be misunderstanding you but you seem to be under the impression that the jquery mobile JS is either a substitute for or includes the base level jquery library. This is not the case. To make jquery mobile work you need the base level jquery library first. The head of any jquery mobile page include the following...
jquery.mobile-1.0rc2.min.css
jquery-1.6.4.min.js
jquery.mobile-1.0rc2.min.js
Once you have those assets in the page, you can find the position of an element like this...
var position = $("#idOfElementOrSomeOtherSelector").position();
alert("the element is at top: "+position.top+" left: "+position.left );
I'm not sure how this changes with PhoneGap but with any luck, this should give you a clue.
精彩评论