2
使用してください:可視で動作していません。jQuery可視セレクタが動作しない
$('.landscape:visible')
または$('.landscape').filter(':visible')
どちらも私の目標は、目に見える風景写真が何であれの変数を作成し、それは高さだつかむ、そして一貫性を保つためにポートレート画像にそれを適用することです。
テスト目的で、第3のナビゲーションボタン#w
は、その高さが変数vincent
を使用して書き込むように設定されています。
テストサイト:http://brantley.dhut.ch/
はJavaScript:
(function($){
$.respond = function(callback) {
var element = $('#main');
$('.z').hide();
$(document).ready(function() {
dimensions();
});
$(window).load(function() {
dimensions();
$('#load').fadeOut('fast', function() {
$('.z:first').fadeIn('slow');
$('footer').fadeIn('slow');
});
});
$(window).resize(function() {
dimensions();
});
//Adjust image size
function dimensions() {
return element.each(function() {
var i = $('.z', element);
$(i).each(function(){
var browserWidth = $(window).width();
var imgRatio = $(this).width()/$(this).height()
var availableHeight = ($(window).height() - $('header').height() - $('footer').height() - 80)
var browserRatio = browserWidth/availableHeight
var zzz = $('.z').height();
/* resize functions
$(this).height(availableHeight).width('auto');
$(this).width(browserWidth - 40).height('auto');
*/
/* image sizing logic */
if (imgRatio >= 1) {
$(this).addClass('landscape');
}
var vincent = $('.landscape').filter(':visible').height();
if (browserRatio >= imgRatio) {
if (availableHeight <= 312) {
/* Landscape */
$('body').css('background', 'yellow');
$(this).width(browserWidth - 40).height('auto');
} else {
$(this).height(availableHeight).width('auto');
$('body').css('background', 'green');
}
} else {
if (availableHeight <= 312) {
/* Portrait */
$('body').css('background', 'yellow');
$(this).height(200).width('auto');
} else {
$(this).width(browserWidth - 40).height('auto');
$('body').css('background', 'blue');
}
}
/* horizontally center content */
$(this).css('margin-left', (browserWidth - $(this).width())/2);
$('#w').text(vincent);
});
return false;
});
};
//callback();
};
})(jQuery);