问题描述
一直试图让这个工作几个小时,但无法找到解决方案,所以一些建议将不胜感激!我在 if($ window.width()语句中有一个函数,它也在这个语句之外运行。所以当窗口宽度> 1000 px该功能也火灾..我的问题很简单..为什么?
我使用可正常工作的背景颜色'记录'if / else语句,颜色在调整大小时来回变化。当页面为< 1000px右侧列表应该在视觉上表现为带有标签功能的下拉列表(与电梯下拉列表功能相同),当页面大于1000时,右侧应该可视化地显示为标签。
(使其更容易滚动)
解决方案第一次在大于1000px的窗口中打开页面时,它会设置单击事件处理程序。当您将其大小调整为小于1000像素的宽度时,点击事件仍处于设置状态,因此点击时它仍会发生反应。
您可以执行以下操作:
当宽度大于1000px时
$('。schedule li')。bind('click',function(){...
其他(宽度小于1000像素)取消绑定。
$('。schedule li')。unbind('click');
I希望这是有帮助的。
have been trying to get this to work for some hours now but can't find the solution so some advice would be much appreciated! I have a function within an if ($window.width() < 1000)
statement which also runs outside of this statement.. So when the window width is > 1000 px the function also fires.. My question is simple.. Why?
I'm 'logging' the if/else statement with the background colour which works fine, the colour changes back and forth when resizing.. When the page is < 1000px the right side list should be visually represented as a dropdown with tab functionality (same functionality as the dropdown list on the lift), and when the page is > 1000 the right side should be visually represented as tabs.
Full screen demo (makes it easier to scroll)
解决方案 The first time you open the page in a window large than 1000px it sets the click event handler. When you resize it to a width smaller than 1000px, the click event is still set, so it will still react when you click.
You can do the following:
When the width is larger than 1000px
$('.schedule li').bind('click', function(){...
else (width is smaller than 1000px) unbind the click.
$('.schedule li').unbind('click');
I hope this is helpfull.
这篇关于if语句中的函数也在if语句之外运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!