I’m fading in/out pictures on the click of 3 buttons (button22, button23, button25). Almost everything works fine, apart from the fact that the click event somehow doesn’t follow the right order.
When I click button22, it should do the following:
First it fades out image1,
Then via the Case statement, due to clicking of button22, it sets image1 to that link
Then it fades in image1, showing actually the image behind the link from button22.
However what it does:
First it fades out image1
Then it fades in image1 without switching the source (‘src’), so you still see the same picture it just faded out, no matter what button you clicked.
Then it QUICKLY switches the picture when it’s already back at 100% opacity. So it’s fading in with the old source behind it, although it has already passed the case statement.
@russian-dima but you know that the .then() that Igor used is equivalent to your await, so the correction is not really correction.
The problem is that it takes a short time to the new image to render and in this short time the old image is still there.
So the solution will be either to use 2 images (only one them is shown at each specific time), and replace the src of the hidden image before you start to fading out the other image. OR to use a single image but add a short timeout before you start fading it in.
@jonatandor35
I tested my given code. it seems to work good.
And yes, because you have eliminated all my other AWAITs, now it looks like it is not a correction anymore (Yes i know about then , but i do not like to use it.)
But fact is, that my simple example works, just like it should.
the first image fades out.
the image-src changes…
and then it fades in the new image (image with new src).
I changed my code slightly with the ‘async’ function combined with ‘await’ and am now perfectly able to change the duration of the fade in/out effects! Thanks a bunch
Attention!!! This solution is not perfect, like i figured out, right now.
When cklicking on next button to fast —> some irregular animations appears.
Only if you wait everytime untill animation is done, then everything works perfect.
So i hope you can improve it, or you perhaps already have improved it.