Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it L'avatar di Coralba
    Registrato dal
    Jun 2002
    Messaggi
    185

    Script per adattare lunghezza colonne css

    Salve, sono neofita di Javascript e mi serviva una script per adattare la lunghezza delle colonne in un css e ne ho trovato uno per un template a due colonne.
    Dovevo riadattarlo però per un box_model a TRE colonne.
    Ho fatto le modifiche che mi sembravano appropriate ma lo script non funziona.
    Qualcuno è in grado di dirmi dove sbaglio?
    Posto qui sotto lo script:

    addLoadListener(equalHeight);

    function equalHeight() {

    var myLeftColumn = document.getElementById("center_border_sx");
    var myCenterColumn = document.getElementById("centro_center_border");
    var myRightColumn = document.getElementById("center_border_dx");

    var myLeftHeight = myLeftColumn.offsetHeight;
    var myCenterColumn = myCenterColumn.offsetHeight;
    var myRightHeight = myRightColumn.offsetHeight;

    var myLeftBorderTopPixels = retrieveComputedStyle(myLeftColumn, "borderTopWidth");
    var myLeftBorderBottomPixels = retrieveComputedStyle(myLeftColumn, "borderBottomWidth");
    var myLeftPaddingTopPixels = retrieveComputedStyle(myLeftColumn, "paddingTop");
    var myLeftPaddingBottomPixels = retrieveComputedStyle(myLeftColumn, "paddingBottom");

    var myCenterBorderTopPixels = retrieveComputedStyle(myCenterColumn, "borderTopWidth");
    var myCenterBorderPixels = retrieveComputedStyle(myCenterColumn, "borderBottomWidth");
    var myCenterBorderTopPixels = retrieveComputedStyle(myCenterColumn, "paddingTop");
    var myCenterBordergBottomPixels = retrieveComputedStyle(myCenterColumn, "paddingBottom");

    var myRightBorderTopPixels = retrieveComputedStyle(myRightColumn, "borderTopWidth");
    var myRightBorderBottomPixels = retrieveComputedStyle(myRightColumn, "borderBottomWidth");
    var myRightPaddingTopPixels = retrieveComputedStyle(myRightColumn, "paddingTop");
    var myRightPaddingBottomPixels = retrieveComputedStyle(myRightColumn, "paddingBottom");

    var myLeftBorderNumber = Number(myLeftBorderTopPixels.replace("px", "")) + Number(myLeftBorderBottomPixels.replace("px", ""));
    var myLeftPaddingNumber = Number(myLeftPaddingTopPixels.replace("px", "")) + Number(myLeftPaddingBottomPixels.replace("px", ""));
    var myLeftExtras = myLeftBorderNumber + myLeftPaddingNumber;

    var myCenterBorderNumber = Number(myCenterBorderTopPixels.replace("px", "")) + Number(myCenterBottomPixels.replace("px", ""));
    var myCenterPaddingNumber = Number(myCenterPaddingTopPixels.replace("px", "")) + Number(myCenterPaddingBottomPixels.replace("px", ""));
    var myCenterExtras = myCenterBorderNumber + myCenterPaddingNumber;

    var myRightBorderNumber = Number(myRightBorderTopPixels.replace("px", "")) + Number(myRightBorderBottomPixels.replace("px", ""));
    var myRightPaddingNumber = Number(myRightPaddingTopPixels.replace("px", "")) + Number(myRightPaddingBottomPixels.replace("px", ""));
    var myRightExtras = myRightBorderNumber + myRightPaddingNumber;

    if (myLeftHeight > myRightHeight) {
    myRightColumn.style.height = (myLeftHeight - myRightExtras) + "px";
    }

    else {
    myLeftColumn.style.height = (myRightHeight - myLeftExtras) + "px";
    }


    if (myCenterHeight > myRightHeight) {
    myRightColumn.style.height = (myCenterHeight - myRightExtras) + "px";
    }

    else {
    myCenterColumn.style.height = (myRightHeight - myCenterExtras) + "px";
    }

    if (myLeftHeight > myCenterHeight) {
    myRightColumn.style.height = (myLeftHeight - myCenterExtras) + "px";
    }

    else {
    myLeftColumn.style.height = (myCentertHeight - myLeftExtras) + "px";
    }

    }

    function retrieveComputedStyle(element, styleProperty)
    {
    var computedStyle = null;

    if (typeof element.currentStyle != "undefined")
    {
    computedStyle = element.currentStyle;
    }
    else
    {
    computedStyle = document.defaultView.getComputedStyle(element, null);
    }
    return computedStyle[styleProperty];
    }

    function addLoadListener(fn)
    {
    if (typeof window.addEventListener != 'undefined')
    {
    window.addEventListener('load', fn, false);
    }
    else if (typeof document.addEventListener != 'undefined')
    {
    document.addEventListener('load', fn, false);
    }
    else if (typeof window.attachEvent != 'undefined')
    {
    window.attachEvent('onload', fn);
    }
    else
    {
    var oldfn = window.onload;
    if (typeof window.onload != 'function')
    {
    window.onload = fn;
    }
    else
    {
    window.onload = function()
    {
    oldfn();
    fn();
    };
    }
    }
    }

  2. #2
    Utente di HTML.it L'avatar di Coralba
    Registrato dal
    Jun 2002
    Messaggi
    185
    Esclusi errori di "ortografia"...nessuno che può aiutarmi?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.