Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is there a lazy loading feature ? #62

Closed
salama135 opened this issue May 2, 2021 · 2 comments
Closed

is there a lazy loading feature ? #62

salama135 opened this issue May 2, 2021 · 2 comments

Comments

@salama135
Copy link

No description provided.

@ganeshh123
Copy link

I've found a small workaround for now. It doesn't implement lazy loading, but it reduces the load time for large galleries. The large load comes from loading all the images to measure their height and width for Photoswipe.

If you have thumbnail images, you can switch the code to use the thumbnail's dimensions to figure out an aspect ratio, set a fixed large enough width and calculate a height from it.

Lines 47-60 of load-photoswipe.js

// load the image to check its dimensions
// update the item as soon as w and h are known (check every 30ms)
var img = new Image(); 
img.src = $img.attr('src');
var wait = setInterval(function() {
var w = img.naturalWidth,
	h = img.naturalHeight;
if (w && h) {
	clearInterval(wait);
	ratio = w/h
	item.w = 1920;
	item.h = 1920/ratio;
}
}, 30);

@iranzo
Copy link

iranzo commented Jan 17, 2022

There's a library call b-lazy that allows to do lazy loading of almost anything: https://dinbror.dk/blog/blazy/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants