Skip to content

Instantly share code, notes, and snippets.

@foleyatwork
Last active August 3, 2022 14:37
Show Gist options
  • Save foleyatwork/98134804fa8963b57dd0 to your computer and use it in GitHub Desktop.
Save foleyatwork/98134804fa8963b57dd0 to your computer and use it in GitHub Desktop.
How to run Squarespace's ImageLoader manually.
// 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