当前位置:   article > 正文

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

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

转载于:https://www.cnblogs.com/MrXHong/p/5557099.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/120909?site
推荐阅读
相关标签
  

闽ICP备14008679号