在我的网站上,每个 div 都是根据窗口大小计算的...
// Begin functions
$(document).ready(function(){
$('.wrapper').css({'top' : '0px','left' : '0px'});
$('.wrapper > div').css({'height' : + $(window).height() +'px'});
});
$(document).ready(init);
// Set window height and width variables
var windowheight = $(window).height();
var windowwidth = $(window).width();
// Check monitor sze and workot if incentives needs extra space etc
var bff = 3620 + (1993 - windowwidth);
// Move divs into position
$('.culture').css('top', + - windowheight + 'px');
$('.path').css('top', + - windowheight + 'px');
$('.training').css('top', + - windowheight + 'px');
$('.apply').css({
'top' : + - windowheight + 'px',
'width' : windowwidth + 'px'
});
上面的工作正常,我的问题是,当页面加载后,如果用户然后调整那里的窗口大小,样式将被丢弃,因为 div 已经被加载,jquery 有没有办法检测到这个和然后重新初始化上面的?
最佳答案
是的,您可以在 jQuery 中使用 $(window).resize()
查看窗口是否已调整大小。
http://api.jquery.com/resize/
关于javascript - jQuery 和 CSS 的窗口大小问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14811636/