简体   繁体   中英

Width and height issue with fancybox

When I've added this code no setting on width and height works

jQuery(document).ready(function() {
  $('a.iframe').fancybox(); 
});

What are the options to get around it?

Take a look at the documentation here: http://fancybox.net/api

You're using inline content, so make sure that you're setting the autoDimensions option to false along with the width and height settings.

UPDATE: I tested the following solution successfully:

    $('a.fbtag').fancybox({
        autoDimensions: false,
        height: 300,
        width: 400
    }); 

This assumes that the class name of the link you're opening is 'fbtag'.

Fancy Box width and Height always varies with the media type.

If we provide 5 * 5 pixel image - Fancy Box will show up with dimensions of Image Dimensions.

To counter the effect of media dimensions and define the default width & height for Fancy Box

Try this:

$.fancybox.open(collection.toJSON(), {
   afterShow :function(){},
   maxHeight    : 600,
   minWidth : 500           
}); 

FancyBox width will be minimum - 500 pixels.

FancyBox Height will be proportional to the FancyBox data with maximum Height of 600 pixels.

For example

$.fancybox({
    'content':"This will be the content of the fancybox",
    'width':'500',
    'autoDimensions':false,
    'type':'iframe',
    'autoSize':false
});
$(document).ready(function() {
    $(".fancy-ajax").fancybox({
        type:           'ajax',
        autoDimensions: false,
        'autoSize':     false,
        'height':       'auto'
    });
});

The above codes worked for me. However, I was designing in Twitter Bootstrap.

you can do this two way

With iframe

   $(document).ready(function () {
        $(".fancybox").fancybox({
            width:600,
            height:400,
            type: 'iframe',
            href  : 'url_here'
       });
     })

Without iframe

 $(document).ready(function () {
    $(".fancybox").fancybox({
        width:600,
        height:400,
        autoDimensions: false,
   });
 })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM