jQuery - 在窗口大小调整时调整元素高度以匹配窗口而不刷新 [英] jQuery - resize an elements height to match window without refreshing, on window resize
本文介绍了jQuery - 在窗口大小调整时调整元素高度以匹配窗口而不刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下脚本可以正常刷新页面,但我希望能够动态获取已调整大小的窗口的大小而不刷新页面并将相应的高度应用于某个部分。
I have the following script that works okay if page is refreshed but I want to be able to dynamically get the size of the resized window without refreshing the page and apply respective height to a section.
var w = $(window).width();
var h = $(window).height();
$('section').height(h);
为了让它更动态地工作,我缺少什么?
What am I missing to make it work more dynamically?
推荐答案
尝试以下操作,每次加载或调整窗口大小时都会调用该函数:
Try the following, the function will be called every time the window is loaded or resized:
$(window).on('load resize', function(){
var w = $(window).width();
var h = $(window).height();
$('.section-content').height(h);
});
您在评论中确认部分
应该实际上是 .section-content
。
You confirmed in the comments that section
should in fact be .section-content
.
这篇关于jQuery - 在窗口大小调整时调整元素高度以匹配窗口而不刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文