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];
}

posted @ 2016-06-03 17:42  会飞的夜良  阅读(334)  评论(0编辑  收藏  举报