Event that identifies when the browser is resized.

5

Is there any event javascript that identifies when the browser resizes the page?

I'm having problems with page resizing with a FancyBox window, which loses its dynamic changes and returns the setting when it was opened.

    
asked by anonymous 20.03.2014 / 18:46

2 answers

4

There is.

Javascript

var addEvent = function(elem, type, eventHandle) {
    if (elem == null || typeof(elem) == 'undefined') return;
    if ( elem.addEventListener ) {
        elem.addEventListener( type, eventHandle, false );
    } else if ( elem.attachEvent ) {
        elem.attachEvent( "on" + type, eventHandle );
    } else {
        elem["on"+type]=eventHandle;
    }
};

addEvent(window, "resize", function(){
  console.log("a página foi redimensionada ");
});

jQuery

$(window).resize(function(){
  console.log("a página foi redimensionada ");
})
    
20.03.2014 / 20:01
1

You can do the following:

jQuery

$(function(){

width_inicial=window.innerWidth;
heigth_inicial=window.innerHeight;

setInterval(function(){
  if(window.innerWidth!=width_inicial || window.innerHeight!=heigth_inicial)
  {
    /* seu código */
    alert('a página foi redimensionada');
  }
},1000);

});
    
20.03.2014 / 18:52