画像(このページのサムネイル)を垂直方向に中央揃えするために、これを試しました:
//Center the images (thumbnails) in the slideimg.js
$(document).ready(function() {
$('.work-view img').load(function(){
//get img dimensions
var h = $(this).height();
//alert(h);
//set img position
$(this).css('position','absolute');
$(this).css('top','50%');
$(this).css('margin-top',-Math.round(h/2) + 'px');
});
});
ただし、Chromeでは機能しますが、Firefoxではキャッシュに画像があり、.loadは画像の読み込み専用であるため、Firefoxでは機能しません。だから私はこれを試しています:
//Center the images (thumbnails) in the slideimg.js
$(document).ready(function() {
function imageLoaded() { // function to invoke for loaded image
//get img dimensions
var h = $(this).height();
//alert(h);
//set img position
$(this).css('position','absolute');
$(this).css('top','50%');
$(this).css('margin-top',-Math.round(h/2) + 'px');
}
$('.work-view img').each(function(){
if( this.complete ) {
imageLoaded.call( this );
} else {
$(this).one('load', imageLoaded);
}
});
});
しかし、それは機能しません...$(this).css('position','absolute');
それらを水平に残すのではなく、右にシフトします...私は何か間違ったことをしましたか?