fancybox icon indicating copy to clipboard operation
fancybox copied to clipboard

max width on images and videos

Open Webcreations907 opened this issue 7 years ago • 2 comments

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 😄

Webcreations907 avatar Oct 21 '19 01:10 Webcreations907

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

fancyapps avatar Oct 21 '19 06:10 fancyapps

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-slide padding 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.

jvwrx avatar Oct 30 '20 05:10 jvwrx