max width on images and videos
Aside from adding data-width & height attributes, is there another way to add maxwidth to both images and videos(youtube & vimeo). Mainly just looking for the option on the videos, but if it applies to both that would be great.
Using FancyBox v3.5.7
Thanks 😄
Hi,
You can tweak width/height using afterLoad callback, for example:
$('[data-fancybox="gallery"]').fancybox({
afterLoad : function(instance, current) {
current.width = 480;
current.height = 360;
}
});
Demo - https://jsfiddle.net/2pLunzwg/
btw, current.contentType will be image/video
In case it helps anybody else, I was able to give a max width to videos (and avoid an editor needing to know a video's dimensions or aspect ratio) with CSS:
@media only screen and (min-width: 1000px) {
.fancybox-slide--video {
padding: 44px calc((100% - 1000px + 44px) / 2);
}
}
- Replace 1000px with your desired max width
- 44px is the default
.fancybox-slidepadding but change as needed
Basically, this says "when the viewport is larger than my desired max width, calculate how much left/right padding is needed to always keep us at that width." This ended up being easier than messing with .fancybox-content because Fancybox dynamically changes the width/height of it to keep the video aspect ratio the same as the window resizes.