Human Being
Human Being

Reputation: 8387

How to check if browser window is fully resized or not?

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?

Upvotes: 0

Views: 144

Answers (2)

SauriolJf
SauriolJf

Reputation: 412

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.

Upvotes: 1

b4ttl3m4st3r
b4ttl3m4st3r

Reputation: 106

You can do like this maybe:

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

Upvotes: 0

Related Questions