2015-04-22 2 views
0

Я пробую много вариантов, но все еще не работаю для подходящего размера. В режиме отладки при запуске на «afterLoad» этой линии программа немедленно прекращает работу.Установить Fancybox iframe размер подходит для содержимого image

Мой код:

$('.fancybox').fancybox({ 
    fitToView: false, 
    autoSize: false, 
    type: 'iframe', 
    afterLoad: function() { 
    $('.fancybox-iframe').load(function() { 
     $('.fancybox-inner').height(
     $(this).contents().find('body').height() 
    ); 
     $('.fancybox-inner').width(
     $(this).contents().find('body').width() 
    ); 
    }); 
    } 
}); 

UPDATE: Я нашел решение, не идеальное, но почти. Неправильная работа в Firefox (слишком маленькая), но прямо в Chrome:

afterLoad: function() { 
    this.width = this.content[0].contentDocument.images[0].width; 
    this.height = this.content[0].contentDocument.images[0].height; 
} 

ответ

0

Я нашел решения, но не идеально, но почти. Неправильно работающий в Firefox (слишком маленький), но прямо в Chrome:

afterLoad: function() { 
    this.content[0].contentDocument.images[0].style = ('width: auto; height: auto;'); 
    this.width = this.content[0].contentDocument.images[0].width; 
    this.height = this.content[0].contentDocument.images[0].height; 
} 
0

Если хочет заставить его работать с Firefox, а так использовать .naturalWidth и .naturalHeight

afterLoad: function() { 
    this.content[0].contentDocument.images[0].style = ('width: auto; height: auto;'); 
    this.width = this.content[0].contentDocument.images[0].naturalWidth; 
    this.height = this.content[0].contentDocument.images[0].naturalHeight; 
} 

вместо .width и .height

Смежные вопросы