我有以下的jquery代码来检查窗口的尺寸。不幸的是,它似乎只能提取宽度 - 高度返回为零。我哪里错了?jquery身体的宽度和高度
$(document).ready(function() {
var $window = $('body');
function checkSize() {
var windowWidth = $window.width();
var windowHeight = $window.height();
if (windowWidth < 765) {
$('#index_right').hide();
$('.btn').removeClass("btn-large");
}
else if (windowWidth < 880) {
$('#index_right').hide();
$('.btn').addClass("btn-large");
}
else
{
$('#index_right').fadeIn(1000);
$('.btn').addClass("btn-large");
}
if (windowHeight < 3000) {
//alert(windowHeight);
$('#index_base').hide();
}
else
{
$('#index_base').fadeIn(1000);
}
}
checkSize();
$(window).resize(checkSize);
});
使用'$(窗口)尝试',而不是'$('body')' –
艾米,请查看jQuery给出的例子:http:// api。 jquery.com/height/'$(window).height(); //返回浏览器视口的高度' –