簡単なタスク用にライトボックスのようなコードを作成しています。
私の問題は、画像が読み込まれた後でも高さを取得しようとすると、値が「null」と表示されることです。
コンソールで試しています:
console.log($('#image-wrap img').height());
ここに私の完全なコードがあります:
$(function(){
$.fn.showBig = function(){
$(this).click(function(){
var getURL = $(this).data('url');
$('<div id="darkbg"/>').css({'opacity':'0.5'}).appendTo('body');
$('<div id="popup"/>').css({'opacity':'0'}).appendTo('body');
$('<div id="imageWrap"><img src =' + getURL +'></div>').appendTo('#popup');
$('<span id="close"/>').text('X').appendTo('#popup');
var maxHeight = $(window).height(),
countHeight = $('#image-wrap img').height(),
countWidth = $('#image-wrap img').width(),
countTop = $('#image-wrap img').height()/2,
countLeft = $('#image-wrap img').width()/2;
console.log($('#image-wrap img').height());
$('#image-wrap').css({'height':countHeight+'px', 'width':countWidth+'px'});
$('#popup').css({'margin-left':'-'+countLeft+'px', 'margin-top':'-'+countTop+'px'}).animate({'opacity':'1', 'height':countHeight+'px', 'width':countWidth+'px'})
$('#popup').closeBig();
});
}
$.fn.closeBig = function(){
$(this).on('click', function(){
$('#darkbg, #popup, #close').fadeOut(removeall);
function removeall(){
$(this).remove()
}
});
}
$('#gallery-list li a').showBig();
});
jsfiddle URL: http://jsfiddle.net/mufeedahmad/R2uwq/1/
前もって感謝します。