【发布时间】:2019-10-13 04:57:05
【问题描述】:
我正在使用 jquery,检查窗口宽度并根据屏幕大小触发一个函数。到目前为止一切正常。我的问题是,如果用户在平板电脑/桌面上启动并将视口缩小到我希望功能触发的大小,它应该可以正常工作,但是当他们将屏幕尺寸恢复到平板电脑/桌面时,功能仍然运行,这是我不想要的。有没有办法禁用或终止该功能?
jquery:
$(document.ready(function(){
$(window).on("resize", function (e) {
checkForMobile();
});
checkForMobile();
function checkForMobile() {
var newWindowWidth = $(window).width();
if (newWindowWidth < 768) {
//append nav item to bottom of list mobile and active
$($threePanelNav).click(function () {
var $this = $(this);
$this.appendTo($this.parent());
});
} else {
return false;
}
}
});
【问题讨论】:
-
逻辑是倒退的。改为在点击处理程序中进行宽度检查
-
@charlietfl 所以如果点击事件中的 else 语句?...你有一个例子吗?将不胜感激..感谢您的建议:)
标签: javascript jquery