How To Add Transitions To A Slideshow Using Javascript?
Solution 1:
There are two parts to this answer:
Firstly, visualising the slider
To get two items to fade in, one over the other, you must have two elements. One for the next image and one for the previous image.
Imagine it like a pile of three cards.
On the bottom you have a card with the letter A.
In the middle you have a card with the letter B.
On the top you have a card with the letter C.
- C
- B
- A
Now we want to take card C from the top and put it on the bottom. So we pick it up, move it down the pile and put it under B and A.
- B
- A
- C
As soon as you start visualising it like a deck of physical cards it becomes easier to work with. Cards can either be a hidden card, a covering card or a covered card.
In the case above, C was a covering card (covering B). B was a covered card (covered by C). A was a hidden card (we don't see it at all when we move the cards).
After we move the cards, C became a hidden card (at the bottom of the deck), A became a covered card (covered by B) and B became a covering card.
Likewise the slides of your slider will cover and reveal each other.
When your user presses 'NEXT', you will have to load a picture into the 'covered' slide and slowly fade out the 'covering' slide. When that 'covering' slide fades out, you can move it to hidden. Then you can move the 'covered' slide to 'covering' and the next one down in the pile up to 'covered'.
Your slide-pile will look like this:
- covering
- covered
- hidden
Indeed, you can give these classes to your slides and apply CSS which changes the z-index of your slides.
Secondly, the transitions:
To change opacity of the covering slide, I'd recommend you apply classes to the elements and use CSS to change opacity from 1 to 0 using a css transition. Once the new class is applied, the transition will begin, giving you a smooth transition from one to the next.
Post a Comment for "How To Add Transitions To A Slideshow Using Javascript?"