1
我收聽resize
事件,但我需要擴展它,因爲我在全局使用它。在調用此事件之前,我需要對傳球進行一些額外的檢查。我怎樣才能做到這一點?如何擴展'resize'事件?
我收聽resize
事件,但我需要擴展它,因爲我在全局使用它。在調用此事件之前,我需要對傳球進行一些額外的檢查。我怎樣才能做到這一點?如何擴展'resize'事件?
我要開始說我不完全確定你在問什麼,但希望這會有所幫助。在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);
本次活動將調用瀏覽器的尺寸調整,把你的條件,這裏面做或不做的東西 – Huangism
你不「來電」像這樣的事件。它會自動發生並由瀏覽器自己調用。您不需要中斷該過程,只需在事件處理程序中添加自己的條件邏輯即可。 –