Comparing version 0.1.2 to 0.1.3
{ | ||
"name": "lazyimg", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "图片懒加载", | ||
@@ -5,0 +5,0 @@ "main": "src/adapter.js", |
@@ -21,3 +21,2 @@ /* | ||
function extendStrict(main, sub) { | ||
@@ -33,3 +32,3 @@ var ret = {}; | ||
function applySrc(item, processedSrc) { | ||
function applySrc(item, processedSrc, placeholderSrc) { | ||
if (!processedSrc) { | ||
@@ -40,4 +39,15 @@ return; | ||
item.setAttribute('src', processedSrc); | ||
if (!placeholderSrc) { | ||
return | ||
} | ||
item.onerror = function () { | ||
this.onerror = null; | ||
this.src = placeholderSrc | ||
} | ||
} else { | ||
item.style.backgroundImage = 'url("' + processedSrc + '")'; | ||
var bgStr = 'url("' + processedSrc + '")'; | ||
if (placeholderSrc) { | ||
bgStr += ',url("' + placeholderSrc + '")'; | ||
} | ||
item.style.backgroundImage = bgStr; | ||
} | ||
@@ -54,3 +64,3 @@ } | ||
var item = this; | ||
applySrc(item, item.getAttribute('i-lazy-src')); | ||
applySrc(item, item.getAttribute('i-lazy-src'), item.dataset.placeholder); | ||
item.removeAttribute('i-lazy-src'); | ||
@@ -61,3 +71,2 @@ } | ||
adapter.logConfig = function () { | ||
@@ -67,3 +76,2 @@ console.log('lib-img Config\n', config); | ||
adapter.fire = function () { | ||
@@ -80,3 +88,3 @@ | ||
if (item.dataset.lazy == 'false' && item.dataset.lazy != 'true') { | ||
applySrc(item, processSrc(item, item.getAttribute(config.dataSrc))); | ||
applySrc(item, item.getAttribute(config.dataSrc), item.dataset.placeholder); | ||
} else { | ||
@@ -93,8 +101,4 @@ item.classList.add(label); | ||
adapter.defaultSrc = 'data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg=='; | ||
lib.img = adapter; | ||
@@ -101,0 +105,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
7025
84
0