Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lazyimg

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lazyimg - npm Package Compare versions

Comparing version 0.1.3 to 0.1.5

4

package.json
{
"name": "lazyimg",
"version": "0.1.3",
"version": "0.1.5",
"description": "图片懒加载",

@@ -12,3 +12,3 @@ "main": "src/adapter.js",

{
"name": "mr.raindrop",
"name": "_danz",
"email": "tekkahs@gmail.com"

@@ -15,0 +15,0 @@ }

/*
lib-img-adpter
Author: kongshi.wl@alibaba-inc.com
Date: Dec,2015
lazyimg
Author: _danz
*/

@@ -31,2 +30,15 @@ ;

function preLoadImg (src, loadCallback, errorCallback) {
var img = new Image();
img.src = src
img.onload = loadCallback ? loadCallback.bind(img) : null
img.onerror = errorCallback ? errorCallback.bind(img) : null
}
function dispatchEvent (item, type, data) {
var evt = document.createEvent('CustomEvent')
evt.initCustomEvent(type, false, false, data)
item.dispatchEvent(evt)
}
function applySrc(item, processedSrc, placeholderSrc) {

@@ -46,7 +58,12 @@ if (!processedSrc) {

} else {
var bgStr = 'url("' + processedSrc + '")';
if (placeholderSrc) {
bgStr += ',url("' + placeholderSrc + '")';
}
item.style.backgroundImage = bgStr;
preLoadImg(processedSrc, function () {
item.style.backgroundImage = 'url("' + processedSrc + '")';
item.naturalWidth = this.width
item.naturalHeight = this.height
dispatchEvent(item, 'load')
}, function () {
preLoadImg(placeholderSrc, function () {
item.style.backgroundImage = 'url("' + placeholderSrc + '")';
})
})
}

@@ -53,0 +70,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc