I am trying to create an effect where anytime a user clicks the typewriter image to get a new quote, the previous quote will fade out (opacity: 0) and a new quote will fade in (opacity: 1).
However my code only works once, the first time one clicks for a quote. Where did I go wrong?
Try using jQuery’s .animate(). It allows you to set styles for a duration of time, then tell it what to do after the animation’s finished.
It goes like this:
$('#demo').animate({opacity: 0}, 3000, function() {
// this runs after the 3 second animation finishes
genQuote();
// then add code to reset the opacity back to 1...
});
Thank you for this tip!
My final code JS code is like this and it creates the effect I want. Each time the machine is clicked, the opacity is reset to zero.