我有一个div,我想根据窗口高度调整它的大小。我有一个静态的高度div上面(height=97px)和下面(高度= 200px)。到目前为止,我有以下代码:
function eventSize(){
var windowHeight = $(window).height();
eventHeight = windowHeight - 297;
$('#mainEvent').css('height',eventHeight + 'px');
}
$(document).ready(eventSize);
$(window).resize(eventSize);
代码似乎可以调整大小,但在页面加载时没有显示高度。作为参考,该页面位于以下位置:www.fuelogix.com/test/roi.html。如果这可以用CSS来完成,我也会对这些选项持开放态度。
发布于 2013-07-16 00:48:24
看起来你在那个页面上还有一个坏掉的javascript。这很可能会阻止它工作。错误在这里
$(...).cycle不是midMenu.js第27行中的函数
//Background Cycle
$('#backgroundMid').cycle({
我能够以不同的方式表达你的代码。没有任何问题。
$(function(){
$(window).resize(function(){
var windowHeight = $(window).height();
eventHeight = windowHeight - 297;
$('#mainEvent').css('height',eventHeight + 'px');
}).resize();
});
我的另一个建议是计算偏移量,而不是使用硬编码的297值。
https://stackoverflow.com/questions/17665263
复制相似问题