deblan.io-murph/assets/js/app/px-image.js

28 lines
704 B
JavaScript
Raw Normal View History

2022-09-10 11:12:14 +02:00
class PxImage {
2022-09-08 10:26:58 +02:00
constructor(w) {
this.window = w
}
2022-09-08 10:26:58 +02:00
init() {
const doc = this.window.document
2022-09-10 11:12:14 +02:00
const images = doc.querySelectorAll('.quick-image img, .card-preview img')
2022-09-08 10:26:58 +02:00
for (let i = 0, len = images.length; i < len; i++) {
(function(image) {
const source = image.getAttribute('data-src')
const loader = new Image()
2022-09-08 10:26:58 +02:00
loader.onload = function() {
image.style.backgroundImage = 'url(' + source + ')'
image.style.backgroundSize = 'cover'
}
2022-09-08 10:26:58 +02:00
loader.src = source
})(images[i])
}
}
}
2022-09-10 11:12:14 +02:00
module.exports = PxImage