Javascript trouble changing opacity

Posted by Ghilliedrone on Stack Overflow See other posts from Stack Overflow or by Ghilliedrone
Published on 2014-06-01T02:01:50Z Indexed on 2014/06/01 3:26 UTC
Read the original article Hit count: 89

Filed under:
|

I'm making script that fades 3 pictures out in order, but the pictures' opacity aren't changing. The if statements are reached but the pictures do not change. The first picture changes to 1 opacity on the page load, so I don't see why it wouldn't work in my 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;
 } 
};

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about css