jquery.lazyload (JS懒加载框架使用详解)
Posted 会飞的夜良
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jquery.lazyload (JS懒加载框架使用详解)相关的知识,希望对你有一定的参考价值。
/** 本地加载方式加载JS*/
NSString *path = [[NSBundle mainBundle] pathForResource:@"jquery.js" ofType:nil];
NSString *path2 = [[NSBundle mainBundle] pathForResource:@"jquery.lazyload.js" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
NSURL *url2 = [NSURL fileURLWithPath:path2];
/** 懒加载图片方法*/
NSString *lazyImg = @"<script type=\"text/javascript\">$(function() {$(\"img\").lazyload({effect : \"fadeIn\"});});</script>";
NSString *strCore =[NSString stringWithFormat:@"<script src=\"%@\" type=\"text/javascript\"></script><script src=\"%@\" type=\"text/javascript\"></script>",url,url2];
;
/** 请求头*/
NSString *strHead = [NSString stringWithFormat:@"<html><head>%@<style type=\"text/css\">"
"body { font-family:\"%@\"; color:%@; font-size:%f; }</style>%@</head><body>",
strCore,@"HelveticaNeue-Light", fontColor,
font.pointSize,lazyImg];
/** 请求体*/
NSString *strBody = content;
NSString *strFoot = @"</body></html>";
/** 请求html地址*/
NSString *html =
[NSString stringWithFormat:@"%@%@%@", strHead, strBody, strFoot];
NSLog(@"%@",html);
[self loadHTMLString:html
baseURL:nil];
self.scrollView.scrollEnabled = NO;
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSTimeInterval runInterval = ([CommonUtils currentTimeIntervalDouble] - startTestTime);
DLog(@"页面加载耗时%f秒", runInterval);
// [self closeActivityIndicatorView];
self.alpha = 1;
// 禁用用户选择
[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect=‘none‘;"];
// 禁用长按弹出框
[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout=‘none‘;"];
// Disable bouncing in webview
for (id subview in webView.subviews) {
if ([[subview class] isSubclassOfClass: [UIScrollView class]]) {
[subview setBounces:NO];
}
}
CGFloat mWebViewHeight = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] floatValue];
[self.handleDelegate handlemWebViewHeight:mWebViewHeight webView:self];
}
以上是关于jquery.lazyload (JS懒加载框架使用详解)的主要内容,如果未能解决你的问题,请参考以下文章
jQuery懒加载插件 jquery.lazyload.js
jQuery延迟加载(懒加载)插件 – jquery.lazyload.js