dynamic image dimensions
See original GitHub issueas you said in the docs its not possible, i even tried and went half way through…just one tiny piece missing. here my attempt:
var images = [
{ src: "http://foo.com/bar.gif", w:0, h:0}
];
var pswpElement = document.querySelectorAll('.pswp')[0];
var options = {
index: 0,
showHideOpacity: true
};
var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, images, options);
gallery.listen('imageLoadComplete', function(index, item) {
var img = new Image();
item.w = img.width;
item.h = img.height;
});
gallery.init();
sadly it only works good for the lazyloaded images “left” and “right” but not for the current one requested. in my use case i cant encode the size into the filename as the images are thumbnailed to fit in a box (e.g. image 760+420 should fit in a box of 400x250) and i dont know the resulting dimension, i even dont care 😉. i dont want to make backend requests to get the size, thats not performant. as the example above is half way working i think its possible by PhotoSwipe itself (and it should be a feature anyway 😉 )
i think the easiest fix would be to start all displaying stuff after the event is done?
Issue Analytics
- State:
- Created 9 years ago
- Reactions:5
- Comments:53 (3 by maintainers)
Top Results From Across the Web
How can I resize an image dynamically with CSS as the ...
To make the images flexible, simply add max-width:100% and height:auto . Image max-width:100% and height:auto works in IE7, but not in IE8 (yes,...
Read more >Dynamic image resizing - ImageKit.io
Learn how to dynamically resize & adapt images to fit the page layout by changing URL parameters. No image processing server is required....
Read more >Dynamically resize images - Akamai TechDocs
In addition to resizing images using hard coded dimensions, you can use Image and Video Manager to dynamically resize images based on published...
Read more >Dynamic Dummy Image Generator - DummyImage.com
Dynamic Dummy Image Generator ... Height is optional, if no height is specified the image will be a square. ... Standard image sizes...
Read more >Dynamic Image Sizing (to scale) - Canvas Community
This is ideal for embedding images into your Canvas unit that can be viewed on a mobile with no issues.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Related section in FAQ.
In documentation there is an example on how to add or edit slides dynamically, see http://photoswipe.com/documentation/api.html (at the bottom). You may preload image, retrieve its size, and append (or replace) the dummy image.
Or if you have just 1 or 2 images, you can preload it, and only then initialize PhotoSwipe.
For now there are no plans to add such feature in core, as PhotoSwipe displays and animates image before it’s loaded.
i tried like this , its working for me