fancybox icon indicating copy to clipboard operation
fancybox copied to clipboard

How to set autoSize and autoWidth in fancybox 3?

Open presslayouts opened this issue 9 years ago • 25 comments

Hello

We have set below code in old fancybox, But i need to use in fancybox 3, So how can use/ set autoSize and autoWidth in fancybox 3.

Please give me advice

autoSize: false,
autoWidth : false,

Thank you, PressLayouts.

presslayouts avatar Apr 20 '17 11:04 presslayouts

Hi,

Older versions of fancyBox used JS to size and position html content. In v3 it is done using CSS and therefore there is no need for these options.

You control content dimensions using CSS only - you can now use any CSS values you need, for example, vw/vh units, calc(), etc.

fancyapps avatar Apr 20 '17 11:04 fancyapps

We are sorry, we don't understand you.

At this time display popup in full width but i need to display specific width, So how can manage it, Please give me one example.

Thank you for fast reply.

presslayouts avatar Apr 20 '17 11:04 presslayouts

What content type are you using? Ajax, inline,..?

fancyapps avatar Apr 20 '17 11:04 fancyapps

Ajax type

See below code HTML and js:

HTML Code: <a class="quickview" href="#" data-product_id="187">Quick View</a>

JS Code:

$(document).on('click', '.quickview', function(e) {
	e.preventDefault();
	var pid = $(this).attr('data-product_id');

	$.fancybox.open({
		src  : myAjax.ajaxurl + '?action=fan_product_quickview&pid=' + pid,
		type : 'ajax',
		opts : {
			onComplete : function() {
				$('.flex-control-thumbs').owlCarousel({
					loop: true,
					responsiveClass: true,
					responsiveRefreshRate : 10,
					rtl : fan_rtl,
					nav: true,
					navText: ['',''],
					dots:false,
					items: 3,					
				});	
			}
		}

	});

	return false;
});

Thank you.

presslayouts avatar Apr 20 '17 12:04 presslayouts

Take a look at example from documentation - http://codepen.io/fancyapps/pen/JEoOvK?editors=1100 In this example, ajax response is something like this:

<div class="modal-container">
  <div class="modal-title">Modal title</div>
  <div class="modal-body">
    ...
  </div>
  <div class="modal-footer">..</div>
</div>

This HTML code is inserted into page and, obviously, you can style it however you want, for example:

.modal-container {
  max-width: 500px;
  padding: 0;
  margin: 0;
  border-radius: .3em;
  box-shadow: 0 0.1em 0.4em rgba(0,0,0,.3);
}

fancyapps avatar Apr 20 '17 12:04 fancyapps

Hello fancyapps,

When i added modal-container div, then added extra div automatically, So popup look not good. How can remove this div and resolve our issue. Please see below link and give me hint.

http://prnt.sc/f0wyrn http://prntscr.com/f0wz6t

Thank you in advance !!!

presslayouts avatar Apr 26 '17 05:04 presslayouts

Make sure you have no white-space around your content.

fancyapps avatar Apr 26 '17 06:04 fancyapps

Ooohhhh really good and fast support, Thank you so much.

Resolved my issue.

Thank you again, PressLayouts.

presslayouts avatar Apr 26 '17 06:04 presslayouts

Hi, coming from Fancybox v2 we have a similar question but couldn't find a solution to it. We used autoResize : false and would need the exact same option for v3. The images shall not be enlarged. At least not on the desktop. Scaling them down if they are larger than the viewport would be fine. We experimented with CSS

.fancybox-image {
  max-width:50%; max-height:auto;
}

but this does not work, since: the image is twice the size (shall be displayed at 50% for retina screens) and width/height is not defined in the image tag.

KateMort avatar Oct 11 '17 22:10 KateMort

But what do you mean by " images shall not be enlarged " and " Scaling them down if they are larger than the viewport would be fine ". It is not clear if you want to disable zooming on click or what.

fancyapps avatar Oct 12 '17 06:10 fancyapps

what if you have a two youtube videos and they are both different sizes but you want the lightbox to match the width and height of the video, i saw the example for sizing it with css but how could you add a custom class to the lightbox window that is output when the link is clicked? if i could apply a class per size, then i could write css to match the different sizes. OR if i could just autosize based on the content of the video, that would be best.

robbiegod avatar Nov 12 '17 18:11 robbiegod

You could create links like this:

 <a data-fancybox data-slide-class='customVid' href="https://www.youtube.com/watch?v=8iU8LPEa4o0">
    YouTube
  </a>

and then create CSS class:

.customVid .fancybox-content {
  width: 530px;
  height: 298px;
  max-width: none;
  max-height: none;
}

Demo - https://codepen.io/anon/pen/ooWobY?editors=1100

fancyapps avatar Nov 12 '17 18:11 fancyapps

I'm using fancybox on this page: https://www.mystardr.com/before-after/ear-surgery/

When you click on the image, it then renders it using width I don't want. I know how to set max width, but I want the width to always be greater so it's not screwed up like this. Thanks!

rabbijason avatar Feb 16 '18 22:02 rabbijason

@rabbijason Hi, You are using the first version of fancyBox, it is 8 years old and is no longer supported.

fancyapps avatar Feb 17 '18 08:02 fancyapps

Hi @fancyapps

I'm not starting new topic since my question is related. I have a .mp4 video and FB3 is opening it nicely. Now only problem for me is a black area around the video. Setting size with CSS for fancybox-content work for me but i can't seem to add slideClass to iframe content. The class name don't get added. Maybe you have any better suggestion ?

My html is like that: <a data-fancybox href="http://techslides.com/demos/sample-videos/small.mp4">Click here and watch the video</a>

kristjankoppel avatar Feb 20 '18 20:02 kristjankoppel

@kristjankoppel Just wait for v3.3 where support for aspect ratio will be implemented - https://codepen.io/fancyapps/pen/gopGNq (along with possibility to link directly to video files).

fancyapps avatar Feb 26 '18 10:02 fancyapps

@fancyapps Ahhh that's a delight. I'll wait for this release for sure! What time approximately the release for 3.3 is planned?

kristjankoppel avatar Feb 26 '18 20:02 kristjankoppel

Hi @fancyapps, I can't figure out how to set a max width for my image popup. At the moment it's the full width of the screen. I understand this is not an option anymore in the js and I've tried doing it with css but with no success. Thanks

jeffceriello avatar Mar 16 '18 12:03 jeffceriello

v3.3 has been released and @jeffceriello - there is an example in the docs that show how to custoimize image dimensions.

fancyapps avatar Apr 03 '18 17:04 fancyapps

@fancyapps - Can you clarify where I can find the use of custom image dimensions in the docs? I have just upgraded our site to use 3.3.5 to fix the aspect ratio issues we have with our images but I cannot find the documentation on how to do this for this version - thank you!

chickwithbob avatar Apr 18 '18 00:04 chickwithbob