Salve a tutti, ho un piccolo problemino in php: Io utilizzo il file scripts.php per unire tutti gli script js in un unico file. Ed ecco che qui sorge il problema. Se io scrivo
Codice PHP:
header("Content-Type: text/javascript");
if($_GET['scriptName'] == "effects"){
echo ' function FadeIN(id, timeout) {
var fade = document.getElementById(id);
if(fade.style.opacity < 1){
fade.style.visibility = "visible";
fade.style.display = "";
fade.style.opacity = 0;
if(timeout == "fast"){
FadeINex(id, "20")
}else if(timeout == "slow"){
FadeINex(id, "50")
}else{
FadeINex(id, timeout)
}
}}
var FadeINex = function(id, timeout) {
var fade = document.getElementById(id);
fade.style.opacity = +fade.style.opacity + 0.1;
if(fade.style.opacity < 1.000) {
setTimeout("FadeINex(\'"+id+"', '"+timeout+"\')", timeout);
}}
function FadeOUT(id, timeout){
var fade = document.getElementById(id);
if (fade.style.opacity > 0) {
if(timeout == "fast"){
FadeOUTex(id, "20")
}else if(timeout == "slow"){
FadeOUTex(id, "50")
}else{
FadeOUTex(id, timeout)
}
}
}
var FadeOUTex = function(id, timeout) {
var fade = document.getElementById(id);
fade.style.opacity = fade.style.opacity - 0.1;
if(fade.style.opacity > 0.000) {
setTimeout("FadeOUTex(\'"+id+"', '"+timeout+"\')", timeout);
}else{
fade.style.display = "none";
};};
function slideUP(id, timeout){
if(timeout == "fast"){
slideUPex(id, "3");
}else if(timeout == "slow"){
slideUPex(id, "12");
}else{
slideUPex(id, timeout)
}
}
function slideUPex(id, timeout){
var fade = document.getElementById(id);
fade.style.height = parseInt(fade.style.height) - 2 + "px";
if(parseInt(fade.style.height) > 0){
setTimeout("slideUPex(\'"+id+"', '"+timeout+"\')", timeout);
}else{
fade.style.display = "none";
}}
function slideDOWN(id, timeout){
if(timeout == "fast"){
slideDOWNex(id, "3");
}else if(timeout == "slow"){
slideDOWNex(id, "12");
}else{
slideDOWNex(id, timeout)
}
}
function slideDOWNex(id, timeout){
var heightOriginale = document.getElementById(id).dataset.height;
var fade = document.getElementById(id);
fade.style.display = "";
fade.style.height = parseInt(fade.style.height) + 2 + "px";
if(parseInt(fade.style.height) < heightOriginale){
setTimeout("slideDOWN(\'"+id+"', '"+timeout+"\')", timeout);
}}';
}
Lo script dovrebbe funzionare giusto? Ma non funziona perchè sulla developer console dice: "document.getElementById(...) is null;
fade is null" invece se io creo un file con estensione .js e inserisco dentro il codice funziona perfettamente. Come devo fare per farlo funzionare anche in php?
Grazie in anticipo!