« Italia.it: dalla tomba alla risurrezione | Main | Perchè prendere la rincorsa per sbattere la testa adosso al muro? »
Regolare l’altezza dei DIV in base alla finestra
By Merlinox | February 4, 2008
Un velocissimo script per creare un elemento DIV che si adatti alle dimensioni della finestra. Purtroppo le dimensioni in altezza percentuali via CSS sono ancora un sogno. Forse qualche browser le supporta: comunque non è standard.
Ecco allora un veloce script Javascript che sistema le cose a dovere:
<script type="text/javascript">
window.onload = function(){
resizeMe();
}
window.onresize = function(){
resizeMe();
}
function resizeMe(){
//http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
var myWidth = 0;
var myHeight = 0;
if( typeof( window.innerWidth ) == ‘number’ ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in ’standards compliant mode’
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
document.getElementById(”tree”).style.height = (myHeight - 50) + “px”;
}
</script>
Fatto? Dai provatelo e fatemi sapere se vi funziona bene ![]()
Tags: CSS, HTML, javascript
Post simili
















