jQuery函数在不应该运行时运行 [英] jQuery function running when it shouldn't
问题描述
我有一个函数只需要在宽度小于特定值时运行。我已经用 if($(window).width()< n){} 由于函数也在运行,当它不应该我的页面布局中断单击选项卡,然后调整大小以查看此)。当函数不应该运行常规标签应显示,你可以看到,它们正确显示,直到你点击它们切换(这是该功能被炒鱿鱼,而不应该)。 任何人都可以帮助我? 演示(滚动< and> 1000px to see) PS:我知道这样做会更好用,尽管我只限于使用这个。 如果(windowsize< 1000)您也需要知道当前状态。 您还需要处理在初始调用 I have a function which only needs to run when the width is less then a specific value. I have done this with the The if Since the function is running also when it shouldn't the layout of my page breaks (click the tabs and then resize to see this). When the function should not run regular tabs should be displayed as you can see, they are displayed correctly until you click they toggle (which is the function getting fired whereas it shouldn't). Anyone who can help me? Demo (scroll < and > 1000px to see) PS: I am aware the would be of a better use for although I have been limited to using a for this. Instead of just You also need to handle the case of setting 这篇关于jQuery函数在不应该运行时运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! if($(window).width()
if
颜色变化(浅灰色为< 1000px,深灰色为> 1000px)。
pre $ if(is_large&&& windowsize <1000)
{
is_large = false;
//其余代码处理转换为小尺寸
}
else if(!is_large)
{
is_large = true;
//处理过渡到大尺寸的代码
}
checkWidth()
之前设置 is_large
的页面加载情况。if ($(window).width() < n) { }
but the function also runs when the width is more then n..if ($(window).width() < n) { }
works fine since the background color changes (light gray for < 1000px and dark gray for > 1000px).if (windowsize < 1000)
you also need to know the current status.if (is_large && windowsize < 1000)
{
is_large = false;
// rest of code to handle transition to small size
}
else if (!is_large)
{
is_large = true;
// code to handle transition to large size
}
is_large
on page load before the initial call to checkWidth()
.