Custom width and height on fancybox image

前端 未结 1 1897
深忆病人
深忆病人 2021-01-06 03:56

I wonder if it is posible to set a custom width and height on fancybox images?

As a standard, the width and height of the fancybox changes in relative to the width a

相关标签:
1条回答
  • 2021-01-06 04:49

    A simpler way is to change the size of both, the fancybox opened image AND the fancybox parent container using the beforeShow callback like :

    $(".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;
        }
    });
    

    See JSFIDDLE

    NOTE : this is for fancybox v2.x+


    EDIT (April 2014) :

    With the current version of fancybox (v2.1.5 as today), it's not necessary to apply css rules to the .fancybox-image selector since images are now set to be responsive (max-width: 100%;). this.width and this.height alone will do the trick

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

    See forked JSFIDDLE

    0 讨论(0)
提交回复
热议问题