我侦听resize事件,但我需要扩展它,因为我在全局使用它。在调用此事件之前,我需要对通过进行一些额外的检查。我如何才能做到这一点?
发布于 2017-07-08 08:04:54
我首先要说的是,我不太确定您的要求是什么,但希望这会有一点帮助。在JavaScript中,你不会“调用”像调整大小这样的事件。你倾听它,当它启动时,你会做些什么。
例如,如果(我想您的意思是),您想要在调整窗口大小并满足几个条件后执行某些操作,请尝试如下所示:
<html>
<body onresize = 'myFunction(condition1, condition2, condition3)'>
<div id = 'content'>
<!--your content here-->
</div>
</body>然后对于你的JavaScript:
function myFunction(condition1, condition2, condition3){
if(condition1 && condition2 && condition3){
//code that will execute once resize event fires
//and all three conditions have been met
console.log("Resize event detected, all three conditions have been met");
//your code here
};
}这就是你要找的吗?
您也可以尝试如下所示:
function myFunction(cond1, cond2, cond3(){
if(cond1 && cond2 && cond3){
//code that will execute once resize event fires
//and all three conditions have been met
console.log("Resize event detected, all three conditions have been met");
//your code here
};
}
window.addEventListener("resize", myFunction(cond1, cond2, cond3); https://stackoverflow.com/questions/44832993
复制相似问题