So im trying to give the fadein animation class to author and text , but im kinda stuck, because i want the animation to keep happening after evry button click. and I made function to change the background color to match text and author color, but i dont think the animation matches with the fcc random quote machine fade in and out animation.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Random Quote machine</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<link rel="stylesheet" href="style.css"/>
<script src="https://kit.fontawesome.com/f6bfa81d64.js" crossorigin="anonymous"></script>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"
/>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body>
<div class="container-fluid vh-100 d-flex justify-content-center align-items-center">
<div class="overlay"></div>
<div class="row">
<div id="quote-box" class="border-none text-center h-1 rounded bg-info-subtle col-lg-6 col-sm-6 mx-auto">
<h1 id="text" class="fs-5"></h1>
<p id="author" class="text-end" m10></p>
<div class="d-flex justify-content-between">
<a id="tweet-quote" class="" href="twitter.com/intent/tweet" target="_top"><i class="fa-brands fa-twitter float-left"></i></a>
<button id="new-quote" class="btn btn-primary">new quote</button>
</div>
</div>
<h3 class="text-dark text-center">By Gvain escanilla</h3>
</div>
</div>
<script src="script.js"></script>
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
</body>
</html>
$(document).ready(function(){
function load(){
$.ajax({
url:'https://api.api-ninjas.com/v1/quotes?category=happiness',
method: 'GET',
headers:{
'X-Api-key':'BK7d3nK3VsgCPshkR32ZNA==KHr16qdXYLZSCKwz'
},
success: function(response){
const {quote,author} = response[0];
$('#text').html('<i class="fa-solid fa-quote-left"></i>'+ quote);
$('#author').html('-'+ author);
$('#text').removeClass('animate__animated animate__fadeIn');
$('#author').removeClass('animate__animated animate__fadeIn');
setTimeout(function(){
$('#text').addClass('animate__animated animate__fadeIn');
$('#author').addClass('animate__animated animate__fadeIn');
})
},
error:function(xhr,status,error){
alert('error');
}
});
}
function bgcolor(){
const hex = '0123456789ABCDEF';
let color = '#';
for(let i = 0; i < 6; i++){
color += hex[Math.floor(Math.random() * 16)];
}
return color;
}
load();
let newcolors = bgcolor();
$('.overlay').css({'background-color': newcolors, 'opacity':1});
$("button").click(function(){
load();
const newcolor = bgcolor();
$(".overlay").fadeOut(500,function(){
$(this).css('background-color',newcolor).fadeIn(500);
})
$("#text").animate({opacity:0},500,function(){
$(this).css('color',newcolor).animate({opacity:1},500);
});
$("#author").animate({opacity:0},500,function(){
$(this).css('color',newcolor).animate({opacity:1},500);
});
$("#tweet-quote").animate({opacity:0},500,function(){
$(this).css('background-color',newcolor).animate({opacity:1},500);
});
});
});
.overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: transparent;
z-index: 1;
transition: background-color 0.5s ease;
}
#tweet-quote {
border: none;
background-color: aqua;
padding: 5px;
border-radius: 5px;
}
* {
z-index: 99;
}/*# sourceMappingURL=style.css.map */