views:

192

answers:

3

I have register a trigger on window resize. I want to know how can I trig the event to be called. for example , When hide a div, I want my trigger function can be called.

I found window.resizeTo() can trig the function, but is there any other solution?

+2  A: 

Don't worry about triggering that event. I imagine you have something like:

window.onresize = function() {
    // do a load of stuff
};

Or something similar.

So strip out the "do a load of stuff" into a function like this:

window.onresize = function() {
    doALoadOfStuff();
};

function doALoadOfStuff() {
    //do a load of stuff
}

That way, rather than trying to trigger the resize event, you can just call the doALoadOfStuff function.

Sohnee
A: 

Simply call window.onresize();

Vinz
No, In firebug, I got this: TypeError: window.onresize is not a function
zhongshu
Hmm, have you set the onresize-event? It works on my firefox/IE.Try to paste the following line into your addressbar: javascript:window.onresize=function() { alert("test"); }; window.onresize();
Vinz
Oh, I test your code, just as your expected result. But I attach the onresize event using window.addEventListener('resize',function() { alert("test"); },false); In this situation, windows.onresize() can not be executed.
zhongshu
A: 

If you're using jQuery you can just use:

$(window).resize(function() {

// do stuff

});

jQuery .resize()

Acorn