I’m working through the Front-End Development Certificate, and to try out features of JQuery and other libraries, I’m creating a few projects.
The following is code I’ve written so far for a Christmas e-card.
I plan to have it end with some snowfall. I feel it’s good practice to try to create my own rather than adding a feature that someone else has made that can be added to pages.
At present, I have just created one snowflake, as it’s easier to get that to fall down repeatedly before putting many of them across the page.
However, I’ve tried for the last few hours or more to get it to repeatedly fall down across the page - using a for loop - not using a for loop - but it won’t… I’ve looked at several explanations of how to use animate, but I can’t see why it won’t repeat.
Is it something as simple as the position defined in the CSS? …etc.?
Many thanks in advance.
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<title>Christmas E-Card</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous" />
<script src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" />
</head>
<script>
$(document).ready(function () {
$("#line1, #line2, #line3, #line4, #line5, #line6, #line7, #line8, #line9").hide();
$("#title").hide();
$(".snow1").hide();
$("p").hide();
// $("#title").addClass("animate__animated animate__fadeInLeft");
$("#title").delay(3500).fadeIn(7000);
$("p").delay(10000).fadeIn(7000);
$("p").click(function () {
$("p").fadeOut(2000);
$("#title").fadeOut(4000);
$("#line1").delay(4250).fadeIn(3000).fadeOut(3000);
$("#line2").delay(11000).fadeIn(5000).fadeOut(5000);
$("#line3").delay(21500).fadeIn(3000).fadeOut(3000);
$("#line4").delay(28000).fadeIn(3000).fadeOut(22000);
$("#line5").delay(32500).fadeIn(3000).fadeOut(17500);
$("#line6").delay(39000).fadeIn(3000).fadeOut(11000);
$("#line7").delay(45500).fadeIn(3000).fadeOut(3000);
$("#line8").delay(53000).fadeIn(3000).fadeOut(3000);
$("#line9").delay(59000).fadeIn(3000).fadeOut(3000);
$(".snow1").delay(66000).fadeIn(3000);
});
$(".snow1").click(function () {
setInterval(snowing, 2000);
});
});
function snowing() {
// for (let i = 0; i < 500; i++) {
// $(".snow1").animate({bottom: '0%'}, 'slow').fadeOut();
// i += 1;
// $(".snow").animate({top: '100%'}).fadeIn();
// }
$(".snow1").animate({bottom: '0%'})
$(".snow1").fadeOut()
$(".snow1").animate({top: '100%'}).fadeIn();
}
</script>
<body>
<div class="container-fluid main_container">
<h1 id="title">Begin your Christmas Journey</h1>
<p>By Clicking Here!</p>
<h1 id="line1">I forgot to buy a card...</h1>
<h2 id="line2">Because I've been learning JavaScript, Python, HTML and other code...</h1>
<h1 id="line3">But I can use the skills...</h1>
<h1 id="line4">to create a unique,</h1>
<h1 id="line5">special,</h1>
<h1 id="line6">portfolio-enhancing,</h1>
<h1 id="line7">e-card</h1>
<h1 id="line8">So Happy Christmas</h1>
<h1 id="line9">And Happy New Year</h1>
<div class="snow1">
</div>
<p></p>
<p></p>
<p></p>
<p></p>
</div>
</body>
</html>