-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
65 lines (44 loc) · 1.69 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Let's look at `eq`
var a = $('.artists__name').eq(1); // Miley Cyrus
// Let's look at `siblings` vs `next`
var b = a.siblings(); // `.artists__img` next to Miley
var c = a.siblings('img'); // Empty set, only knows about direct siblings
// If we wanted to get the `img`
a.siblings().find('img');
var d = a.next('.artists__img');
// If we wanted to get the `img` for Prodigy
a.parent().next().find('.artists__img');
// Let's look at `children` vs `find`
var e = $('.artists'); // ol.artists
var f = e.find('.artists__name'); // ["Mark Ronson", "Miley Cyrus", ...]
var g = e.children('.artists__name'); // Returns empty set
// If we know enough about our HTML to get all `.artists__name`
e.children().children('.artists__name');
// Let's look at `parent` vs `parents`
var h = a.parent(); // li containing "Miley Cyrus"
var i = a.parent('.artists'); // Empty Set
// If we know enough about our HTML to get the `.artists`
a.parent().parent('.artists');
var j = a.parents();
var k = a.parents('.artists');
// Let's look at `parents` vs `closest`
var l = a.parents('li'); // Ancestor `li`
var m = a.parents('span'); // Empty set since no ancestor is a span
var n = a.closest('span'); // Span with Miley Cyrus
// For every band name, show the current band when clicked
$('.artists__name').on('click', function() {
var currentlyClicked = $(this);
// Use timeout to smooth out animations
window.setTimeout(() => {
// Show current picture
currentlyClicked.siblings('.artists__img').fadeIn();
}, 400);
// Use timeout to smooth out animations
window.setTimeout(() => {
// hide other images?
currentlyClicked.parent()
.siblings()
.find('.artists__img')
.fadeOut();
}, 0);
});