javascript - Loop elements opacity -
i'm making script fades 3 pictures out in order, pictures' opacity aren't changing. if statements reached pictures not change. first picture changes 1 opacity on page load, don't see why wouldn't work in function.
window.onload = function() { document.getelementbyid("img1").style.opacity = 1; setinterval(swappictures, 2000); }; var swappictures = function(){ if(typeof swappictures.img1v === 'undefined'){ swappictures.img1v = true; } if(typeof swappictures.img2v === 'undefined'){ swappictures.img2v = false; } if(typeof swappictures.img3v === 'undefined'){ swappictures.img3v = false; } if(swappictures.img1v && !swappictures.img2v && !swappictures.img3v){ swappictures.img1v = !swappictures.img1v; swappictures.img2v = !swappictures.img2v; document.getelementbyid("img1").style.opacity = .4; document.getelementbyid("imgtwo").style.opactiy = 1; }else if(!swappictures.img1v && swappictures.img2v && !swappictures.img3v){ swappictures.img2v = !swappictures.img2v; swappictures.img3v = !swappictures.img3v; document.getelementbyid("imgtwo").style.opacity = .4; document.getelementbyid("imgthree").style.opactiy = 1; }else if(!swappictures.img1v && !swappictures.img2v && swappictures.img3v){ swappictures.img3v = !swappictures.img3v; swappictures.img1v = !swappictures.img1v; document.getelementbyid("imgthree").style.opacity = .4; document.getelementbyid("img1").style.opactiy = 1; } };
this need:
var $mppics = document.getelementsbyclassname("mppics"); var n = $mppics.length; var c = 0; function fadeimg(){ for(var i=0; i<n; i++) $mppics[i].style.opacity = 0.4; $mppics[c++%n].style.opacity = 1; } fadeimg(); setinterval(fadeimg, 2000);
Comments
Post a Comment