Javascript 调整窗口大小时调用函数
在调整浏览器窗口大小时,如何调用此(或任何)JS函数再次运行Javascript 调整窗口大小时调用函数,javascript,jquery,window-resize,Javascript,Jquery,Window Resize,在调整浏览器窗口大小时,如何调用此(或任何)JS函数再次运行 <script type="text/javascript"> function setEqualHeight(e) { var t = 0; e.each(function () { currentHeight = $(this).height(); if (currentHeight > t) { t = currentHeigh
<script type="text/javascript">
function setEqualHeight(e) {
var t = 0;
e.each(function () {
currentHeight = $(this).height();
if (currentHeight > t) {
t = currentHeight
}
});
e.height(t)
}
$(document).ready(function () {
setEqualHeight($(".border"))
})
</script>
函数设置相等高度(e){
var t=0;
e、 每个(函数){
currentHeight=$(this).height();
如果(当前高度>t){
t=当前高度
}
});
e、 高度(t)
}
$(文档).ready(函数(){
设置相等高度($(“.border”))
})
您可以使用窗口onresize
事件:
window.onresize = setEqualHeight;
您可以订阅
窗口。onresize
事件()
或
您使用jquery,因此使用方法绑定它
这段代码将添加一个计时器,在调整窗口大小200毫秒后调用resize函数。这将减少方法的调用
var globalResizeTimer=null;
$(窗口)。调整大小(函数(){
if(globalResizeTimer!=null)window.clearTimeout(globalResizeTimer);
globalResizeTimer=window.setTimeout(函数(){
setEqualHeight();
}, 200);
});
big up用于减少方法调用
window.onresize = setEqualHeight;
window.addEventListener('resize', setEqualHeight);
$(window).resize(function () {
setEqualHeight( $('#border') );
});