Created
March 13, 2020 19:01
-
-
Save steve10287/ee1b45ded4bf3456d2b6e6cc19eb01ea to your computer and use it in GitHub Desktop.
Responsive images with Lazysizes
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('lazybeforeunveil', e => { | |
var img = e.target, | |
attr = img.hasAttribute('data-bgset') ? 'data-bgset' : 'data-src', | |
src = img.getAttribute(attr), | |
resize = '/images.php?max_width=' + window.innerWidth + '&imgfile=' + src | |
img.setAttribute(attr, resize) | |
}, false) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment