Skip to content

Commit ea38b9e

Browse files
Add code for sections 2 to 5
0 parents  commit ea38b9e

File tree

69 files changed

+4693
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+4693
-0
lines changed

02.01.fading/css/style.css

+152
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

02.01.fading/index.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<script src="https://code.jquery.com/jquery-1.12.3.min.js" integrity="sha256-aaODHAgvwQW1bFOGXMeX+pC4PZIPsvn2h1sArYOhgXQ=" crossorigin="anonymous"></script>
6+
<script src="js/script.js"></script>
7+
<link rel="stylesheet" href="css/style.css">
8+
<title>The Complete jQuery Course - Course Code</title>
9+
</head>
10+
<body>
11+
<div id="content">
12+
<h1>The Complete jQuery Course - Project Structure</h1>
13+
14+
<div class="red-box">Red</div>
15+
<div class="green-box">Green</div>
16+
<div class="blue-box">Blue</div>
17+
<div class="clear"></div>
18+
</body>
19+
</html>

02.01.fading/js/script.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
$(function () {
2+
// Fade out element over 2000ms
3+
$(".red-box").fadeOut(2000);
4+
5+
// Fade back in over 1000ms
6+
$(".red-box").fadeIn(1000);
7+
8+
// Fade element to specific opacity (here 50%)
9+
$(".blue-box").fadeTo(1000, 0.5);
10+
11+
// Note that the blue box animation starts right away, whereas the second
12+
// red box animation waits until the first animation finished.
13+
// This is because each element has its own animation queue which is
14+
// executed one after the other. So while the red box is still "busy" with
15+
// its first animation, the second animation waits in the queue.
16+
17+
// Fade element in or out, depending on current status
18+
$(".blue-box").fadeToggle();
19+
$(".blue-box").fadeToggle();
20+
21+
// Notice that fadeToggle fades back to the blue box's previous opacity,
22+
// thus only back to 50% opacity.
23+
});

02.02.fading-pitfalls/css/style.css

+152
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

02.02.fading-pitfalls/index.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<script src="https://code.jquery.com/jquery-1.12.3.min.js" integrity="sha256-aaODHAgvwQW1bFOGXMeX+pC4PZIPsvn2h1sArYOhgXQ=" crossorigin="anonymous"></script>
6+
<script src="js/script.js"></script>
7+
<link rel="stylesheet" href="css/style.css">
8+
<title>The Complete jQuery Course - Course Code</title>
9+
</head>
10+
<body>
11+
<div id="content">
12+
<h1>The Complete jQuery Course - Project Structure</h1>
13+
14+
<div class="red-box">Red</div>
15+
<div class="green-box">Green</div>
16+
<div class="blue-box">Blue</div>
17+
<div class="clear"></div>
18+
</body>
19+
</html>

02.02.fading-pitfalls/js/script.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
$(function () {
2+
// Fade out element over 2000ms
3+
$(".red-box").fadeOut(2000);
4+
5+
// Try to use fadeTo
6+
$(".red-box").fadeTo(1000, 1.0);
7+
8+
// This doesn't work because fadeOut() will set display: none and fadeTo
9+
// doesn't modify the display property. Thus, it's not able to make it
10+
// reappear.
11+
12+
// Back to original state
13+
$(".red-box").fadeIn(100);
14+
15+
// To keep red box in the layout, use only fadeTo
16+
$(".red-box").fadeTo(2000, 0);
17+
18+
// Can now make it re-appear in the way we tried above
19+
$(".red-box").fadeTo(1000, 1.0);
20+
});

0 commit comments

Comments
 (0)