2014-04-22 2 views
1

Fotorama 4.5.0 (Rails gem)을 사용하고 있으며 API 객체를 가져 오는 데 문제가 있습니다.fotorama : API 객체를 가져올 수 없습니다. (정의되지 않음)

페이지로드 Fotorama는 숨겨진 div에 있습니다. 클릭하면 모달로 열립니다.

$objects = $('*[rel="fotorama"]') 
$fotorama_div = $('.fotorama') 

$fotorama_div 
.on('fotorama:showend', (e, fotorama, extra) -> 
    // resizing fotorama 
).fotorama() 
fotorama = $fotorama_div.data('fotorama') 
console.log(fotorama) // here is undefined 

$objects.on 'click', -> 
    // finding index of an image 
    modal.open({content: $('#fotorama-container')}) 
    fotorama.show(index) // index is ok 

이 코드 fotorama 객체는 항상 undefined입니다 :
다음은 코드 (커피)입니다. 개체의 첫 번째 클릭 후

$objects = $('*[rel="fotorama"]') 
$fotorama_div = $('.fotorama') 

$fotorama_div 
.on('fotorama:showend', (e, fotorama, extra) -> 
    // resizing fotorama 
).fotorama() 
fotorama = $fotorama_div.data('fotorama') 
console.log(fotorama) // here is undefined 

$objects.on 'click', -> 
    // finding index of an image 
    modal.open({content: $('#fotorama-container')}) 
    if typeof fotorama == "undefined" 
    fotorama = $fotorama_div.data('fotorama') 
    console.log(fotorama) // here is undefined after the first click on object 
    fotorama.show(index) // index is ok 

-fotorama 여전히 undefined,하지만 난 모달를 폐쇄하고 두 번째 클릭을하고있어 후 - 나는 fotorama 객체와 모든 작품을 얻을 :
좋아, 나는 수표와 if 추가 예상대로

그리고 콘솔에서 $fotorama_div.data('fotorama')을 수행하면 작동합니다.

페이지로드시 fotorama 개체를 어떻게 얻을 수 있습니까?

답변

1

정확히 똑같은 문제가있었습니다. div에 fotorama를로드하면 콘솔에 "undefined"가 표시되고 div를 다시 표시하면 fotorama 객체가 올바르게로드 된 것입니다.

"display : none;"이 (가)있는 객체에서 fotorama를로드하는 원인을 발견했습니다. CSS 스타일. 나는 이유를 모른다. 그러나 fotorama가 숨겨져있는 무언가에 적재한다면 그것은 깨진다.

나는 RoR을 모르지만 모달을 처음 보여줄 것입니다. 그러면 모달을 연 후 fotorama $fotorama_div.fotorama()을 열면됩니다.

관련 문제