Event that identifies when the browser is resized.

Asked

Viewed 1,050 times

5

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

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

2 answers

4


There is yes.

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 ");
})

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);

});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.