javascript - jQuery 和 CSS 的窗口大小问题

标签 javascript jquery html css

在我的网站上,每个 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/

相关文章:

javascript - AngularJs - $http.get 不工作

javascript - 邮政信箱正则表达式在包含单词 "box"的地址上失败

javascript - 使用 javascript 连续生成 div(tiles),除了标记为 0 的以外,所有大小都相同

javascript - 创建时分配动态 <div> 唯一 ID

html - AngularJS 字段验证表达式似乎在 ng-show 中不起作用

javascript - JS : Input user name and print it out

Javascript 迭代器不起作用

javascript - 如何在javascript上获取单元格值进行确认?

javascript - SlidesJS 隐藏只工作一次

jquery - 使用 CSS3 动画或 jQuery 将 div 向下滑动到可见区域