Question

Is there a way to make the below script apply to just iframe in fancybox? I have a page with both gallery and iframe. I want the iframe to have different heights without affecting the image sizes.

$('.fancybox').fancybox({
afterLoad: function () {
    this.width = $(this.element).data("width");
    this.height = $(this.element).data("height");
}
});
Was it helpful?

Solution

You can set a condition to validate the type of content before passing the data-* values to fancybox like :

$(".fancybox").fancybox({
    afterLoad: function () {
        if (this.type == "iframe") {
            this.width = $(this.element).data("width");
            this.height = $(this.element).data("height");
        };
    }
});

JSFIDDLE


You could also refer to $(this) like this.element

$(".fancybox").fancybox({
    afterLoad: function () {
        if (this.type == "iframe") {
            this.width = this.element.data("width");
            this.height = this.element.data("height");
        };
    }
});

JSFIDDLE

OTHER TIPS

this code work for me!

$.fancybox.open({
        maxWidth: 1263,
        // fitToView: true,
        width: '90%',
        // maxHeight: 292,
        autoSize: false,
        closeClick: false,
        openEffect: 'elastic',
        closeBtn: true,
        closeEffect: 'elastic',
        href: '/team/' + $(this).data("cv") + '_team.html',
        type: 'iframe',
        'afterShow': function() {
          $(".fancybox-wrap").height($(".fancybox-iframe").contents().find("html").height() + 30);
          $(".fancybox-skin").height($(".fancybox-iframe").contents().find("html").height());
          $(".fancybox-inner").height($(".fancybox-iframe").contents().find("html").height());
        }
    });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top