0

この js が Firefox では機能しないのに、IE と Chrome では意図したとおりに完全に機能する理由について、誰かが洞察を提供できるかどうか疑問に思っていましたか?

ページ上部のいくつかのボタンにカーソルを合わせると、多くの div の色が変わります。

私のサイトで見ることができます: ptable.info

window.onload=function(){
var noblegasesColl = document.getElementsByClassName('noblegases');
var halogensColl = document.getElementsByClassName('halogens');
var othernonmetalsColl = document.getElementsByClassName('othernonmetals');
var transitionmetalsColl = document.getElementsByClassName('transitionmetals');
var metalloidsColl = document.getElementsByClassName('metalloids');
var posttransitionColl = document.getElementsByClassName('posttransition');
var alkalineColl = document.getElementsByClassName('alkaline');
var alkaliColl = document.getElementsByClassName('alkali');
var actinoidsColl = document.getElementsByClassName('actinoids');
var lanthanoidsColl = document.getElementsByClassName('lanthanoids');

//Noble Gases
document.getElementById('noblegasesButton').addEventListener('mouseover', function(){
    changeColor(halogensColl, '#696969');
    changeColor(othernonmetalsColl, '#696969');
    changeColor(transitionmetalsColl, '#696969');
    changeColor(metalloidsColl, '#696969');
    changeColor(posttransitionColl, '#696969');
    changeColor(alkalineColl, '#696969');
    changeColor(alkaliColl, '#696969');
    changeColor(actinoidsColl, '#696969');
    changeColor(lanthanoidsColl, '#696969');
});
document.getElementById('noblegasesButton').addEventListener('mouseout', function(){
    changeColor(halogensColl, '#00FFFF');
    changeColor(othernonmetalsColl, '#7CFC00');
    changeColor(transitionmetalsColl, '#ff78bb');
    changeColor(metalloidsColl, '#7A378B');
    changeColor(posttransitionColl, '#8FBC8F');
    changeColor(alkalineColl, '#e5e500');
    changeColor(alkaliColl, '#FF6600');
    changeColor(actinoidsColl, '#f4a460');
    changeColor(lanthanoidsColl, '#CC1100');
    changeColor(actinoidsColl, '#f4a460');
});
//Halogens
document.getElementById('halogensButton').addEventListener('mouseover', function(){
    changeColor(noblegasesColl, '#696969');
    changeColor(othernonmetalsColl, '#696969');
    changeColor(transitionmetalsColl, '#696969');
    changeColor(metalloidsColl, '#696969');
    changeColor(posttransitionColl, '#696969');
    changeColor(alkalineColl, '#696969');
    changeColor(alkaliColl, '#696969');
    changeColor(actinoidsColl, '#696969');
    changeColor(lanthanoidsColl, '#696969');
});

document.getElementById('halogensButton').addEventListener('mouseout', function(){
    changeColor(halogensColl, '#00FFFF');
    changeColor(othernonmetalsColl, '#7CFC00');
    changeColor(transitionmetalsColl, '#ff78bb');
    changeColor(metalloidsColl, '#7A378B');
    changeColor(posttransitionColl, '#8FBC8F');
    changeColor(alkalineColl, '#e5e500');
    changeColor(alkaliColl, '#FF6600');
    changeColor(noblegasesColl, '#3399CC');
    changeColor(lanthanoidsColl, '#CC1100');
    changeColor(actinoidsColl, '#f4a460');
});
//Non-metals
document.getElementById('nonmetalsButton').addEventListener('mouseover', function(){
    changeColor(halogensColl, '#696969');
    changeColor(noblegasesColl, '#696969');
    changeColor(transitionmetalsColl, '#696969');
    changeColor(metalloidsColl, '#696969');
    changeColor(posttransitionColl, '#696969');
    changeColor(alkalineColl, '#696969');
    changeColor(alkaliColl, '#696969');
    changeColor(actinoidsColl, '#696969');
    changeColor(lanthanoidsColl, '#696969');                    
});

document.getElementById('nonmetalsButton').addEventListener('mouseout', function(){
    changeColor(halogensColl, '#00FFFF');
    changeColor(othernonmetalsColl, '#7CFC00');
    changeColor(transitionmetalsColl, '#ff78bb');
    changeColor(metalloidsColl, '#7A378B');
    changeColor(posttransitionColl, '#8FBC8F');
    changeColor(alkalineColl, '#e5e500');
    changeColor(alkaliColl, '#FF6600');
    changeColor(noblegasesColl, '#3399CC');
    changeColor(lanthanoidsColl, '#CC1100');
    changeColor(actinoidsColl, '#f4a460');
});
//Transition metals
document.getElementById('transitionmetalsButton').addEventListener('mouseover', function(){
    changeColor(halogensColl, '#696969');
    changeColor(othernonmetalsColl, '#696969');
    changeColor(noblegasesColl, '#696969');
    changeColor(metalloidsColl, '#696969');
    changeColor(posttransitionColl, '#696969');
    changeColor(alkalineColl, '#696969');
    changeColor(alkaliColl, '#696969');
    changeColor(actinoidsColl, '#696969');
    changeColor(lanthanoidsColl, '#696969');        
});

document.getElementById('transitionmetalsButton').addEventListener('mouseout', function(){
    changeColor(halogensColl, '#00FFFF');
    changeColor(othernonmetalsColl, '#7CFC00');
    changeColor(transitionmetalsColl, '#ff78bb');
    changeColor(metalloidsColl, '#7A378B');
    changeColor(posttransitionColl, '#8FBC8F');
    changeColor(alkalineColl, '#e5e500');
    changeColor(alkaliColl, '#FF6600');
    changeColor(noblegasesColl, '#3399CC');
    changeColor(lanthanoidsColl, '#CC1100');
    changeColor(actinoidsColl, '#f4a460');
});
//Post-transition
document.getElementById('posttransitionButton').addEventListener('mouseover', function(){
    changeColor(halogensColl, '#696969');
    changeColor(othernonmetalsColl, '#696969');
    changeColor(transitionmetalsColl, '#696969');
    changeColor(metalloidsColl, '#696969');
    changeColor(noblegasesColl, '#696969');
    changeColor(alkalineColl, '#696969');
    changeColor(alkaliColl, '#696969');
    changeColor(actinoidsColl, '#696969');
    changeColor(lanthanoidsColl, '#696969');
});

document.getElementById('posttransitionButton').addEventListener('mouseout', function(){
    changeColor(halogensColl, '#00FFFF');
    changeColor(othernonmetalsColl, '#7CFC00');
    changeColor(transitionmetalsColl, '#ff78bb');
    changeColor(metalloidsColl, '#7A378B');
    changeColor(posttransitionColl, '#8FBC8F');
    changeColor(alkalineColl, '#e5e500');
    changeColor(alkaliColl, '#FF6600');
    changeColor(noblegasesColl, '#3399CC');
    changeColor(lanthanoidsColl, '#CC1100');
    changeColor(actinoidsColl, '#f4a460');
});
//Metalloids
document.getElementById('metalloidsButton').addEventListener('mouseover', function(){
    changeColor(halogensColl, '#696969');
    changeColor(othernonmetalsColl, '#696969');
    changeColor(transitionmetalsColl, '#696969');
    changeColor(noblegasesColl, '#696969');
    changeColor(posttransitionColl, '#696969');
    changeColor(alkalineColl, '#696969');
    changeColor(alkaliColl, '#696969');
    changeColor(actinoidsColl, '#696969');
    changeColor(lanthanoidsColl, '#696969');
});

document.getElementById('metalloidsButton').addEventListener('mouseout', function(){
    changeColor(halogensColl, '#00FFFF');
    changeColor(othernonmetalsColl, '#7CFC00');
    changeColor(transitionmetalsColl, '#ff78bb');
    changeColor(metalloidsColl, '#7A378B');
    changeColor(posttransitionColl, '#8FBC8F');
    changeColor(alkalineColl, '#e5e500');
    changeColor(alkaliColl, '#FF6600');
    changeColor(noblegasesColl, '#3399CC');
    changeColor(lanthanoidsColl, '#CC1100');
    changeColor(actinoidsColl, '#f4a460');
});
//Alkaline
document.getElementById('alkalineButton').addEventListener('mouseover', function(){
    changeColor(halogensColl, '#696969');
    changeColor(othernonmetalsColl, '#696969');
    changeColor(transitionmetalsColl, '#696969');
    changeColor(metalloidsColl, '#696969');
    changeColor(posttransitionColl, '#696969');
    changeColor(noblegasesColl, '#696969');
    changeColor(alkaliColl, '#696969');
    changeColor(actinoidsColl, '#696969');
    changeColor(lanthanoidsColl, '#696969');
});

document.getElementById('alkalineButton').addEventListener('mouseout', function(){
    changeColor(halogensColl, '#00FFFF');
    changeColor(othernonmetalsColl, '#7CFC00');
    changeColor(transitionmetalsColl, '#ff78bb');
    changeColor(metalloidsColl, '#7A378B');
    changeColor(posttransitionColl, '#8FBC8F');
    changeColor(alkalineColl, '#e5e500');
    changeColor(alkaliColl, '#FF6600');
    changeColor(noblegasesColl, '#3399CC');
    changeColor(lanthanoidsColl, '#CC1100');
    changeColor(actinoidsColl, '#f4a460');
});
//Alkali
document.getElementById('alkaliButton').addEventListener('mouseover', function(){
    changeColor(halogensColl, '#696969');
    changeColor(othernonmetalsColl, '#696969');
    changeColor(transitionmetalsColl, '#696969');
    changeColor(metalloidsColl, '#696969');
    changeColor(posttransitionColl, '#696969');
    changeColor(alkalineColl, '#696969');
    changeColor(noblegasesColl, '#696969');
    changeColor(actinoidsColl, '#696969');
    changeColor(lanthanoidsColl, '#696969');
});

document.getElementById('alkaliButton').addEventListener('mouseout', function(){
    changeColor(halogensColl, '#00FFFF');
    changeColor(othernonmetalsColl, '#7CFC00');
    changeColor(transitionmetalsColl, '#ff78bb');
    changeColor(metalloidsColl, '#7A378B');
    changeColor(posttransitionColl, '#8FBC8F');
    changeColor(alkalineColl, '#e5e500');
    changeColor(alkaliColl, '#FF6600');
    changeColor(noblegasesColl, '#3399CC');
    changeColor(lanthanoidsColl, '#CC1100');
    changeColor(actinoidsColl, '#f4a460');
});
//Lanthanoids
document.getElementById('lanthanoidsButton').addEventListener('mouseover', function(){
    changeColor(halogensColl, '#696969');
    changeColor(othernonmetalsColl, '#696969');
    changeColor(transitionmetalsColl, '#696969');
    changeColor(metalloidsColl, '#696969');
    changeColor(posttransitionColl, '#696969');
    changeColor(alkalineColl, '#696969');
    changeColor(alkaliColl, '#696969');
    changeColor(actinoidsColl, '#696969');
    changeColor(noblegasesColl, '#696969');
});

document.getElementById('lanthanoidsButton').addEventListener('mouseout', function(){
    changeColor(halogensColl, '#00FFFF');
    changeColor(othernonmetalsColl, '#7CFC00');
    changeColor(transitionmetalsColl, '#ff78bb');
    changeColor(metalloidsColl, '#7A378B');
    changeColor(posttransitionColl, '#8FBC8F');
    changeColor(alkalineColl, '#e5e500');
    changeColor(alkaliColl, '#FF6600');
    changeColor(noblegasesColl, '#3399CC');
    changeColor(lanthanoidsColl, '#CC1100');
    changeColor(actinoidsColl, '#f4a460');
});
//Actinoids
document.getElementById('actinoidsButton').addEventListener('mouseover', function(){
    changeColor(halogensColl, '#696969');
    changeColor(othernonmetalsColl, '#696969');
    changeColor(transitionmetalsColl, '#696969');
    changeColor(metalloidsColl, '#696969');
    changeColor(posttransitionColl, '#696969');
    changeColor(alkalineColl, '#696969');
    changeColor(alkaliColl, '#696969');
    changeColor(noblegasesColl, '#696969');
    changeColor(lanthanoidsColl, '#696969');
});

document.getElementById('actinoidsButton').addEventListener('mouseout', function(){
    changeColor(halogensColl, '#00FFFF');
    changeColor(othernonmetalsColl, '#7CFC00');
    changeColor(transitionmetalsColl, '#ff78bb');
    changeColor(metalloidsColl, '#7A378B');
    changeColor(posttransitionColl, '#8FBC8F');
    changeColor(alkalineColl, '#e5e500');
    changeColor(alkaliColl, '#FF6600');
    changeColor(noblegasesColl, '#3399CC');
    changeColor(lanthanoidsColl, '#CC1100');
    changeColor(actinoidsColl, '#f4a460');
});

}

function changeColor(coll, color){

    for(var i=0, len=coll.length; i<len; i++)
    {
        coll[i].style["background-color"] = color;
    }
}
4

1 に答える 1