This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* findLazyElements() { | |
const blocks = [ | |
...Array.from(document.querySelectorAll("noscript.lazyload")).map(lazy => | |
parseHTML(lazy.innerText).map(elem => ({ elem, parent: lazy.parentNode })) | |
), | |
...Array.from(document.querySelectorAll("template.lazyload")).map(lazy => | |
Array.from(lazy.content.cloneNode(true).children) | |
.map(elem => ({ elem, parent: lazy.parentNode })) | |
.map(item => { | |
if (item.elem.tagName !== "SCRIPT") return item; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.wrapper { | |
position: relative; | |
overflow: hidden; | |
padding-bottom: $mainRatio; | |
background-size: cover; | |
img { | |
position: absolute; | |
left: -10000%; | |
right: -10000%; | |
top: -10000%; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numbers = [1, 2, 3, 4, 5] | |
console.time('Imperative') | |
function squared(numbers) { | |
let arr = [] | |
for ( let i = 0; i < numbers.length; i++ ) { | |
arr.push( numbers[i] * numbers[i] ) | |
} | |
return console.log(arr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener("DOMContentLoaded", () => { | |
const lazyImages = [...qall(".lazy-load")] | |
if (!lazyImages) return; | |
if ("IntersectionObserver" in window) { | |
let lazyImageObserver = | |
new IntersectionObserver((entries, observer) => { | |
entries.forEach(entry => { | |
if (entry.isIntersecting) { | |
let lazyImage = entry.target; |