-
-
Save sorcamarian/ed6d567a3b2085c921e6066fdea68d8a to your computer and use it in GitHub Desktop.
How to run Squarespace's ImageLoader manually.
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
// For all images. | |
var allImages = document.querySelectorAll('img[data-src]'); | |
for (var i = 0; i < allImages.length; i++) { | |
ImageLoader.load(allImages[i]); | |
} | |
// For a single image. | |
var myImage = document.getElementById('my-image'); | |
ImageLoader.load(myImage); | |
// Optional paramaters. | |
var myImage = document.getElementById('my-image'); | |
ImageLoader.load(myImage, { | |
// Can be set to true, false, or "viewport". | |
// "viewport" loads the dimensions but not the | |
// image itself. | |
load: true, | |
// Can be set to 'fit', 'fill', or null. Fit | |
// maintains the aspect ratio without letting | |
// the image get larger than the container. | |
// Fill autocrops the image into a container. | |
// null just loads the image with no layout | |
// applied. | |
mode: 'fill' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment