AJAX查询处于活动状态时禁用窗口大小调整
Disabling window resize when AJAX query active
我有一个jQuery脚本,它是一个搜索脚本,但也包含在调整窗口大小时将元素调整为(屏幕高度-40px)的功能。但是,当搜索(AJAX查询)处于活动状态时,我想禁用调整大小功能。有人知道我该怎么做吗
我当前的代码是:
$(document).ready(function(){
$(window).resize(function(){
if($(window).height()<1200){
$("#a").height($(window).height()-40);
}
});
$("form").submit(function(a){
a.preventDefault();
if($("#i").val().length>0){
$.ajax({
type:"get",
url:"search.php?q="+q,
dataType:"html",
success:function(a){
...
}
})
}
})
})
使用.on()和.of()
$(document).ready(function(){
function started(){
if($(window).height()<1200){
$("#a").height($(window).height()-40);
}
$(window).on("resize.name_space",started);
$("form").submit(function(a){
a.preventDefault();
if($("#i").val().length>0){
$(window).off("resize.name_space");
$.ajax({
type:"get",
url:"search.php?q="+q,
dataType:"html",
success:function(a){
$(window).on("resize.name_space",started); ...
}
})
}
})
})
var loading;
...
if($(window).height()<1200 && !loading){
...
loading = true;
$.ajax({
...
complete: function(){
loading = false;
}.
})
}
})
试试这个,它在ajax运行时添加了一个签入,并将阻止进行重新调整大小
$(document).ready(function(){
//Create the variable
var check = false;
$(window).resize(function(){
//Is the ajax currently running? This if statement runs if the answer is no
if (check == false && $(window).height()<1200 ) {
$("#a").height($(window).height()-40);
}
});
$("form").submit(function(a){
a.preventDefault();
//Set the variable to true, this stops the resizing above ^^
check = true;
if($("#i").val().length>0){
$.ajax({
type:"get",
url:"search.php?q="+q,
dataType:"html",
success:function(a){
...
},
complete: function() {
//Set back to off once the ajax has finished
check = false;
}
})
}
})
})
相关文章:
- 窗口大小调整事件在ie7中持续触发
- 根据窗口大小调整 HTML 中 SVG 图像的大小
- 在浏览器窗口大小调整时更改 JS 逻辑
- 提示不同的Javascript/JQuery在窗口大小调整为低于/高于设置宽度时显示
- AJAX查询处于活动状态时禁用窗口大小调整
- 如何计算窗口大小调整的大小更改百分比
- jQuery:窗口大小调整功能问题
- 满足某些条件时窗口大小调整和文档加载的 jQuery
- 如何运行窗口大小调整函数
- Craftyjs 在窗口大小调整时重绘
- 浏览器窗口大小调整的 JavaScript 功能
- 当窗口大小调整到 480px 以下时调用函数
- j查询窗口大小调整和媒体查询
- 打开/关闭模式窗口会触发窗口大小调整
- JS或jQuery或窗口大小调整或窗口宽度小于npx时
- 禁用浏览器窗口大小调整
- 单击输入字段触发器窗口大小调整
- 调整大小后,窗口大小调整事件中断切换
- jQuery - 移动元素,其子元素由窗口大小调整触发
- 如何避免由其他事件触发的多次窗口大小调整