本文主要包含hbuilder mui,hbuilder mui视频教程,hbuilder mui教程,hbuilder mui api,hbuilder mui app等相关知识,教程希望在学习及工作中可以帮助到您
");
</div>
1.页面先引入[async.js](https://github.com/caolan/async)
2.本地缓存的代码使用到了[这个链接](http://www.bcty365.com/content-146-2588-1.html)
建议在懒加载前给img一个默认图片
2.本地缓存的代码使用到了[这个链接](http://www.bcty365.com/content-146-2588-1.html)
建议在懒加载前给img一个默认图片
- /**
- * 将网络图片下载到本地并显示,包括缓存 www.bcty365.com
- */
- (function(lazyimg) {
- lazyimg.lazyLoad = function(doc, cb) {
- lazyLoad(doc ? doc : document);
- }
- var lazyLoad = function(doc, cb) {
- var imgs = doc.querySelectorAll('img.lazy');
- async.each(imgs, function(img, cb1) {
- var data_src = img.getAttribute('data-src');
- if (data_src && data_src.indexOf('http://') >= 0) {
- common.cache.getFile(data_src, function(localUrl) {
- setPath(img, localUrl);
- });
- }
- }, function() {
- cb && cb();
- });
- }
- function setPath(img, src) {
- img.setAttribute('src', src);
- img.classList.remove("lazy");
- }
- }(window.Lazyimg = {}));
- 使用
- var getImgs=function(cb){
- var imgs=document.querySelectorAll("img");
- imgs=mui.slice.call(imgs);
- imgs.forEach(function(item, index, array) {
- item.setAttribute("data-src", "远程链接")
- });
- cb&&cb();
- }
- getImgs(function(){
- Lazyimg.lazyLoad();
- });