Pergunta

The code to make a div height equal to its width below:

$('div').height($('div').width());

However if you manually resize the browser window the height will not update - you need to refresh the page. Any idea how to correct it?

Foi útil?

Solução

You need to bind your code on the window.onresize event :

window.onresize=function(){
  $('div').height($('div').width());
};

The doc : http://www.w3schools.com/jsref/event_onresize.asp

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top