Skip to content

Commit 25ea4ff

Browse files
committed
Completed wesbos#13 & wesbos#14
1 parent cbbc5b3 commit 25ea4ff

File tree

2 files changed

+64
-6
lines changed

2 files changed

+64
-6
lines changed

13 - Slide in on Scroll/index-START.html

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,29 @@ <h1>Slide in on Scroll</h1>
5858
};
5959
}
6060

61+
const sliderImages = document.querySelectorAll('.slide-in');
62+
63+
function checkSlide(e) {
64+
sliderImages.forEach(sliderImage => {
65+
66+
// Half-way through the image
67+
const slideInAt = (window.scrollY + window.innerHeight) -
68+
sliderImage.height / 2;
69+
const imageBottom = sliderImage.offsetTop + sliderImage.height;
70+
71+
const isHalfShown = slideInAt > sliderImage.offsetTop;
72+
const isNotScrolledPast = window.scrollY < imageBottom;
73+
74+
if (isHalfShown && isNotScrolledPast) {
75+
sliderImage.classList.add('active');
76+
} else {
77+
sliderImage.classList.remove('active');
78+
}
79+
})
80+
}
81+
82+
window.addEventListener('scroll', debounce(checkSlide));
83+
6184
</script>
6285

6386
<style>
@@ -68,11 +91,11 @@ <h1>Slide in on Scroll</h1>
6891
font-size: 20px;
6992
font-weight: 200;
7093
}
71-
94+
7295
body {
7396
margin: 0;
7497
}
75-
98+
7699
*, *:before, *:after {
77100
box-sizing: inherit;
78101
}
@@ -101,13 +124,13 @@ <h1>Slide in on Scroll</h1>
101124

102125
.slide-in {
103126
opacity: 0;
104-
transition: all .5s;
127+
transition: all .35s;
105128
}
106129

107130
.align-left.slide-in {
108131
transform: translateX(-30%) scale(0.95);
109132
}
110-
133+
111134
.align-right.slide-in {
112135
transform: translateX(30%) scale(0.95);
113136
}

14 - JavaScript References VS Copying/index-START.html

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,28 @@
88

99
<script>
1010
// start with strings, numbers and booleans
11+
let age = 100;
12+
let age2 = age;
13+
console.log(age, age2);
14+
15+
age = 200;
16+
console.log(age, age2);
17+
18+
let name = 'Wes';
19+
let name2 = name;
20+
console.log(name, name2);
21+
name = 'Wesley';
22+
console.log(name, name2);
1123

1224
// Let's say we have an array
1325
const players = ['Wes', 'Sarah', 'Ryan', 'Poppy'];
1426

1527
// and we want to make a copy of it.
28+
const team = players;
1629

1730
// You might think we can just do something like this:
31+
team[3] = 'Lux';
32+
// console.log(team, players);
1833

1934
// however what happens when we update that array?
2035

@@ -27,29 +42,49 @@
2742
// So, how do we fix this? We take a copy instead!
2843

2944
// one way
45+
const team2 = players.slice();
3046

3147
// or create a new array and concat the old one in
48+
const team3 = [].concat(players);
3249

3350
// or use the new ES6 Spread
51+
const team4 = [...players];
52+
const team5 = Array.from(players);
3453

3554
// now when we update it, the original one isn't changed
3655

3756
// The same thing goes for objects, let's say we have a person object
38-
3957
// with Objects
4058
const person = {
4159
name: 'Wes Bos',
4260
age: 80
4361
};
4462

4563
// and think we make a copy:
64+
const captain = person;
65+
captain.number = 99;
4666

4767
// how do we take a copy instead?
68+
const cap2 = Object.assign({}, person, { number: 199 });
69+
70+
// Below Syntax Coming Soon
71+
// const cap3 = {...person};
4872

4973
// We will hopefully soon see the object ...spread
5074

5175
// Things to note - this is only 1 level deep - both for Arrays and Objects. lodash has a cloneDeep method, but you should think twice before using it.
52-
76+
const wes = {
77+
name: 'Wes',
78+
age: 100,
79+
social: {
80+
twitter: '@wesbos',
81+
facebook: 'wesbos.developer'
82+
}
83+
}
84+
85+
// Only one level deep
86+
// Won't deep clone nested objs w/i obj
87+
const dev = Object.assign({}, wes);
5388
</script>
5489

5590
</body>

0 commit comments

Comments
 (0)