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

29 lines
765 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-25 20:43:24 +02:00
const images = doc.querySelectorAll('.quick-image img, .card figure 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-14 11:02:41 +02:00
image.style.backgroundPosition = 'center'
2022-09-08 10:26:58 +02:00
}
2022-09-08 10:26:58 +02:00
loader.src = source
})(images[i])
}
}
}
2022-09-10 11:12:14 +02:00
module.exports = PxImage