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
개체를 어떻게 얻을 수 있습니까?