问题描述
我是JavaScript新手。我想知道如何在用户完成调整窗口大小后创建一个onresize函数以在另一个函数中触发一个函数。很可能会发生会话超时。
关于编写基本函数的任何想法?
< script type =text / javascript>
window.onresize = function(){
//第一个函数在调整大小时发生
//然后当用户
}完成窗口大小调整时发生函数2
< / script>
这是我正在尝试的修改版本。目标是在页面大小调整时隐藏页面上的主胶囊div。最初,当onresize事件触发时,div的可见性将变成一个待机屏幕,说请等待我们处理信息。
脚本实验:
var resizeTimeout;
window.onresize = function(){
clearTimeout(resizeTimeout);
document.getElementById(loading)。className =loading-visible;
document.getElementById('XXXDIV')。style.visibility ='hidden';
for(var h = 1; h {
document.getElementById('DesignXXX'+ h).style.visibility ='hidden';
}
resizeTimeout = setTimeout(function(){
var hideDiv = function(){document.getElementById(loading)。className =loading-invisible;};
var oldLoad = window.onload;
var newLoad = oldLoad?function(){hideDiv.call(this); oldLoad.call(this);}:hideDiv;
location.reload(true)= newLoad;
document.getElementById('XXXDIV')。style.visibility ='visible';
for(var h = 1; h {
document.getElementById('DesignXXX'+ h).style.visibility ='visible';
}
},2000); //设置为1/4秒。可能需要调整。
};
< / script>
在jQuery网站上有一个对resize事件的评论:b
$ b
I'm new to JavaScript. I am trying to figure out how I would create an onresize function to fire a function during and another one after the user is done resizing the window. Most likely a session timeout will occur.
Any ideas on writing a basic function?
<script type="text/javascript">
window.onresize = function () {
// The first function goes here while resizing is happening
// Then function 2 occurs when window resizing is finished by the user
}
</script>
Here is the modified version of what I am attempting. The goal is to hide the main capsule div on a page while the page is resizing. Initially when the onresize event is triggered is turns on a div's visibility to be a stand by screen saying "please wait while we process the information".
The Script Exp:
var resizeTimeout;
window.onresize = function() {
clearTimeout(resizeTimeout);
document.getElementById("loading").className = "loading-visible";
document.getElementById('XXXDIV').style.visibility = 'hidden';
for ( var h = 1; h < 40; h++)
{
document.getElementById('DesignXXX' + h ).style.visibility = 'hidden';
}
resizeTimeout = setTimeout(function() {
var hideDiv = function(){document.getElementById("loading").className = "loading-invisible";};
var oldLoad = window.onload;
var newLoad = oldLoad ? function(){hideDiv.call(this);oldLoad.call(this);} : hideDiv;
location.reload(true) = newLoad;
document.getElementById('XXXDIV').style.visibility = 'visible';
for ( var h = 1; h < 40; h++)
{
document.getElementById('DesignXXX' + h ).style.visibility = 'visible';
}
}, 2000); // set for 1/4 second. May need to be adjusted.
};
</script>
On the jQuery website there is a comment to resize event:
这篇关于window.onresize:在调整过程中以及调整大小时触发一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!