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
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;
} 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.