简体   繁体   中英

Exit a resize event

I'm having issues exiting a resize event. I have some operations i want to do whenever the browser window is being resized. However after the resizing event has finished i have some further code that i wan't to be executed. Due to the resizing event not finishing the code that exceeds this event are not being executed.

Is there a way to finalize the event or should the resizing event be implemented in another way? How do i get doMoreStuff() to be executed after the resizing?

Code example:

$(window).resize(function (){
    doStuff();
});

doMoreStuff();

You can do it in two ways.

  1. Inside the resize eventhandler, after your other code:
$(window).resize(function() {
  doStuff();
  doMoreStuff();
});
  1. If you want it to be asynchron (so the eventhandler can finish):
$(window).resize(function() {
  doStuff();
  settimeout(function() {
    doMoreStuff();
  }, 0);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM