svelte-lazy
Advanced tools
Comparing version 0.1.8 to 0.1.9
60
index.js
@@ -774,33 +774,33 @@ (function (global, factory) { | ||
function throttle(func, wait, options) { | ||
let context, args, result; | ||
let timeout = null; | ||
let previous = 0; | ||
if (!options) options = {}; | ||
const later = function() { | ||
previous = options.leading === false ? 0 : new Date(); | ||
timeout = null; | ||
result = func.apply(context, args); | ||
if (!timeout) context = args = null; | ||
}; | ||
let context, args, result; | ||
let timeout = null; | ||
let previous = 0; | ||
if (!options) options = {}; | ||
const later = function() { | ||
previous = options.leading === false ? 0 : new Date(); | ||
timeout = null; | ||
result = func.apply(context, args); | ||
if (!timeout) context = args = null; | ||
}; | ||
return function(event) { | ||
const now = new Date(); | ||
if (!previous && options.leading === false) previous = now; | ||
const remaining = wait - (now - previous); | ||
context = this; | ||
args = arguments; | ||
if (remaining <= 0 || remaining > wait) { | ||
if (timeout) { | ||
clearTimeout(timeout); | ||
timeout = null; | ||
} | ||
previous = now; | ||
result = func.apply(context, args); | ||
if (!timeout) context = args = null; | ||
} else if (!timeout && options.trailing !== false) { | ||
timeout = setTimeout(later, remaining); | ||
} | ||
return result; | ||
}; | ||
} | ||
return function(event) { | ||
const now = new Date(); | ||
if (!previous && options.leading === false) previous = now; | ||
const remaining = wait - (now - previous); | ||
context = this; | ||
args = arguments; | ||
if (remaining <= 0 || remaining > wait) { | ||
if (timeout) { | ||
clearTimeout(timeout); | ||
timeout = null; | ||
} | ||
previous = now; | ||
result = func.apply(context, args); | ||
if (!timeout) context = args = null; | ||
} else if (!timeout && options.trailing !== false) { | ||
timeout = setTimeout(later, remaining); | ||
} | ||
return result; | ||
}; | ||
} | ||
@@ -807,0 +807,0 @@ function instance($$self, $$props, $$invalidate) { |
@@ -6,3 +6,4 @@ { | ||
"main": "index.js", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"repository": "leafOfTree/svelte-lazy", | ||
"scripts": { | ||
@@ -9,0 +10,0 @@ "test": "rollup -c ./test/rollup.config.js -w", |
# svelte-lazy | ||
<p align="center"> | ||
<img alt="demo image" src="https://raw.githubusercontent.com/leafOfTree/leafOfTree.github.io/HEAD/svelte-lazy.gif" width="300" height="300" /> | ||
</p> | ||
A svelte component to lazyload any content including images. | ||
@@ -28,3 +32,3 @@ | ||
> The Number value use `px` as unit. | ||
> The Number value use `px` as unit. | ||
@@ -37,5 +41,4 @@ - `fadeOption: Object` Default: `{ delay: 0, duration: 400 }`. Option for the fade transition. Set `null` to disable. | ||
See [demo](https://svelte.dev/repl/6d7714fa3cce4909af6c6d187271e0a1?version=3.6.10) here. | ||
See [demo on svelte.dev/repl](https://svelte.dev/repl/6d7714fa3cce4909af6c6d187271e0a1?version=3.6.10). | ||
<img alt="demo image" src="https://raw.githubusercontent.com/leafOfTree/leafOfTree.github.io/HEAD/svelte-lazy.gif" width="300" height="300" /> | ||
@@ -47,3 +50,3 @@ ## Development | ||
# Open test/index.html or open a local server | ||
# Open test/index.html or start a local server | ||
serve test | ||
@@ -50,0 +53,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
53951
54