码迷,mamicode.com
首页 > Web开发 > 详细

jquery.lazyload (JS懒加载框架使用详解)

时间:2016-06-03 18:55:55      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:

 /** 本地加载方式加载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懒加载框架使用详解)

标签:

原文地址:http://www.cnblogs.com/MrXHong/p/5557099.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!