View Single Post
Old 01-24-2013, 07:01 AM   PM User | #3
d'Anconia
Regular Coder

 
d'Anconia's Avatar
 
Join Date: Jan 2010
Location: Tempe, AZ
Posts: 143
Thanks: 15
Thanked 5 Times in 5 Posts
d'Anconia is an unknown quantity at this point
Yeah I decided the best way to do it was to modify and use a setTimeout function within a for loop. For some reason it seems like it is not going through the loop correctly though. Here is the relevant part of my code:

Code:
    function fade(currentTime, newAverage, newColor) {
        if (currentTime <= 5){
            var currentOpacity = 1.0 - (currentTime * .2);
            document.getElementById('rating').style.opacity = currentOpacity;
            document.getElementById('logo').style.width = "500";
        }
        if(currentTime >= 5){
            var ratingAverage = document.getElementById('rating_average');
            ratingAverage.innerHTML = (newAverage);
            //now time to change the ratings color
            var entityRating = document.getElementById('rating');
            entityRating.style.color = newColor;
            var currentOpacity = currentTime * 2 - 1.0;
            document.getElementById('rating').style.opacity = currentOpacity;
            }
        }   

document.getElementById('rating').style.opacity = 1.0;                 
for (var timer = 0; timer < 10; timer++){
    setTimeout(function(){fade(timer, preciseResponseAverage, starResponseColor)}, 100);
    }
I was hoping for a slow fade but am not getting that. Currently it's not even changing the opacity at all when I click on it, nor the color of the text. In fact I added the logo.style.width = 500 line specifically to test to see whether it's even looping at all and it appears that it's not because the logo on the page is not changing to 500px (whether I include the 'px' or not). It's will change the actual rating itself though...

Edit: Heck I even got it to change the color but when it changes there is no opacity fade at all. It's like Javascript is only executing the final part of the loop or something...

PS For the record I am using Chrome.
__________________
Powerful ideas for all lovers of personal and political freedom:
Freedomain Radio
Free Talk Live

Last edited by d'Anconia; 01-24-2013 at 07:15 AM..
d'Anconia is offline   Reply With Quote