0

I want to execute one function, after my window is fully resized.

window.resizeTo('792','115');

myFunction();

My question :

1.Does the myFunction() method will be called only after the window is fully resized ?

2.If yes mean no problem for me, else I want the below scenario ?

My need :

I need a pure Javascript solution.

if(windowIsFullyResized){
      myFunction();
}else{
      // wait for window resize and again call myFunction();
}

How can I achieve this?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Human Being
  • 8,269
  • 28
  • 93
  • 136

2 Answers2

1

Like it says here, you can do this :

I prefer to create an event:

$(window).bind('resizeEnd', function() {
    //do something, window hasn't changed size in 500ms
});

Here is how you create it:

 $(window).resize(function() {
        if(this.resizeTO) clearTimeout(this.resizeTO);
        this.resizeTO = setTimeout(function() {
            $(this).trigger('resizeEnd');
        }, 500);
    });

You could have this in a global javascript file somewhere.

Community
  • 1
  • 1
SauriolJf
  • 412
  • 2
  • 10
0

You can do like this maybe:

$( window ).resize(function() {
    var windowWidth = $(window).width();
    var windowHeight = $(window).height();
    if(windowWidth == 792 && windowHeight == 115) myFUnction();
});
b4ttl3m4st3r
  • 106
  • 11