Uncaught TypeError: Error in Fade In

0

Hi! I am using this code to do a fade in. The fade in works. The problem is that if you click something before the fade in finishes completely, this error appears, continuously! And it never ends!

 "code.js:366 Uncaught TypeError: Cannot read property 'style' of null
 at generalFadein (code.js:366)
 at FadeInPagina2hist1 (code.js:346)". 

I suppose it's something related to the clear interval or something. Maybe it's even more basic, but I can not figure it out ... Thank you !!

var pagina2hist1timer;
var pagina2hist2timer;
var pagina2hist3timer;
var pagina2textotimer;


function startFadeInPagina2(){
window.setTimeout(function() 
{pagina2hist1timer=window.setInterval(FadeInPagina2hist1,35);}, 250);
window.setTimeout(function() 
{pagina2hist2timer=window.setInterval(FadeInPagina2hist2,40);},300);
window.setTimeout(function() 
{pagina2hist3timer=window.setInterval(FadeInPagina2hist3,45);},350);
window.setTimeout(function() 
{pagina2textotimer=window.setInterval(FadeInPagina2texto,30);},200);

}



function FadeInPagina2hist1(){
generalFadein(pagina2hist1timer, 
document.getElementById("hist1"),0.02);

}

function FadeInPagina2hist2(){
generalFadein(pagina2hist2timer, 
document.getElementById("hist2"),0.02);

}

function FadeInPagina2hist3(){
generalFadein(pagina2hist3timer, 
document.getElementById("hist3"),0.02);

}

function FadeInPagina2texto(){
generalFadein(pagina2textotimer, 
document.getElementById("textoabrigo"), 0.02);

}
function generalFadein(timer, myImg, speed) {

if (myImg.style.opacity == "") {
    img.style.opacity = "0.0";
}

var opacity = Number(myImg.style.opacity);
if (opacity < 1) {
    opacity = opacity + speed;
    myImg.style.opacity = "" + opacity;
}
else {
    window.clearInterval(pagina2hist1timer);
    window.clearInterval(pagina2hist2timer);
    window.clearInterval(pagina2hist3timer);
    window.clearInterval(pagina2textotimer);
}
}
    
asked by anonymous 05.06.2018 / 19:17

0 answers