我想添加一个事件监听器,以便每当我调整窗口大小时就调用一个函数,但是不知何故,它不起作用!我尝试了这些代码,但没有用!
$(function(){$(window).resize(titleResize);});
$(function(){$(window).resize(titleResize());});
$(window).resize(titleResize);
$(window).resize(titleResize());
有什么主意吗?
顺便说一句,这是我的titleResize函数:
function titleResize() {
maxHeight = 0;
$("div.lae-entry-text-wrap > h3").each(function(){
titleHeight = $(this).height();
if (titleHeight > maxHeight){
maxHeight = titleHeight;
}
});
$("div.lae-entry-text-wrap > h3").css("height", maxHeight);
}
答案 0 :(得分:1)
尝试关注
$(window).resize(function(){
alert('Window Is Resized')
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
答案 1 :(得分:1)
在Script
之后,您的函数正在调用
$(window).resize(function(){
debugger
titleResize();
});
function titleResize() {
alert('Function titleResize() Called');
maxHeight = 0;
$("div.lae-entry-text-wrap > h3").each(function(){
titleHeight = $(this).height();
if (titleHeight > maxHeight)
{
maxHeight = titleHeight;
}
});
$("div.lae-entry-text-wrap > h3").css("height", maxHeight);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
答案 2 :(得分:0)
尝试这样
$(window).on('resize', function(){ //Your code });
$(window).on('resize', function(){
console.log('resize')
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
答案 3 :(得分:0)
我也遇到了同样的问题,您可以使用这种类型的代码来解决错误
$(window).resize( () => {
let Width = $(window).width();
if (Width > 910) {
$(".navbar1").hide();
}
})