Jump to content

[SOLVED] Boolien alternative


gli

Recommended Posts

Hi! I'm begginer to JavaScript.

 

Heres my code

 

var opacity = 0;
function fadeout() {

    if(opacity <= 1) {

        opacity = opacity + 0.1;

        document.getElementById('imgMid').style.opacity=opacity;

        window.setTimeout('fadeout()', 60);
}
} 

 

It's working but only once, because i have slideshow, and on next picture, the opacity variable is 1, and i tried many ways but i can't get it work for all slideshow. Please can you give me way in what i can do that.

Yes i tried 'for loops' and 'while' but nothing hapenned.

Thanks

Link to comment
https://forums.phpfreaks.com/topic/111574-solved-boolien-alternative/
Share on other sites

It would make sense to make a loop instead of recursively calling the function so that you can set the opacity variable each time the function is called. If you don't want to do that, I think it would work to just set the opacity back to 0 and return once the fade is done:

var opacity = 0;
function fadeout() {

    if(opacity <= 1) {

        opacity = opacity + 0.1;

        document.getElementById('imgMid').style.opacity=opacity;

        window.setTimeout('fadeout()', 60);
}
else
        opacity = 0;
} 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.