fancybox图像上的自定义宽度和高度

The*_*XxE 4 jquery height width fancybox

我想知道在fancybox图像上设置自定义宽度和高度是否可行?

作为标准,fancybox的宽度和高度相对于图像的宽度和高度而变化,但我希望在所有图像中都是800宽度和600高度.

我想在Facebook上为图像框创建一些熟悉的东西,您可以在其中看到左侧的图像,以及右侧的描述和注释.

如果有人可以帮助我,这可能会很棒...... :)

  • TheYaXxE

JFK*_*JFK 19

一种更简单的方法是使用beforeShow回调更改两者的大小,fancybox打开的图像和fancybox父容器:

$(".fancybox").fancybox({
    fitToView: false, // avoids scaling the image to fit in the viewport
    beforeShow: function () {
        // set size to (fancybox) img
        $(".fancybox-image").css({
            "width": 800,
            "height": 600
        });
        // set size for parent container
        this.width = 800;
        this.height = 600;
    }
});
Run Code Online (Sandbox Code Playgroud)

请参阅JSFIDDLE

注意:这适用于fancybox v2.x +


编辑(2014年4月):

使用当前版本的fancybox(今天的v2.1.5),没有必要将css规则应用于.fancybox-image选择器,因为图像现在设置为response (max-width: 100%;).this.width而且this.height独自一人会做到这一点

$(".fancybox").fancybox({
    fitToView: false,
    beforeShow: function () {
        this.width = 800;
        this.height = 600;
    }
});
Run Code Online (Sandbox Code Playgroud)

请参阅forked JSFIDDLE