Skip to content

Commit 4ae2220

Browse files
author
Jin Xu
committed
course wesbos#13 finished
1 parent 4d8d1d7 commit 4ae2220

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

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

61+
window.onload = function() {
62+
var imgInfo = [];
63+
64+
[...document.querySelectorAll('img')].forEach((ele, idx) => {
65+
imgInfo.push({
66+
'dom': ele,
67+
'top': ele.offsetTop,
68+
'height': ele.offsetHeight
69+
})
70+
})
71+
72+
window.addEventListener('scroll', e => {
73+
imgInfo.forEach((info, idx) => {
74+
if(((window.scrollY) >= (info.top + .5 * info.height - window.innerHeight)) && ((window.scrollY) <= (info.top + 1.5 * info.height - .5 * window.innerHeight))){
75+
(info.dom).classList.add('active')
76+
}
77+
else {
78+
(info.dom).classList.remove('active')
79+
}
80+
})
81+
})
82+
}
6183
</script>
6284

6385
<style>

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
10. [x] ~~Hold Shift and Check Checkboxes~~
1717
11. [ ] Custom Video Player
1818
12. [x] ~~Key Sequence Detection~~
19-
13. [ ] Slide in on Scroll
19+
13. [x] ~~Slide in on Scroll~~
2020
14. [ ] JavaScript References vs. Copying
2121
15. [ ] LocalStorage
2222
16. [ ] Mouse Move Shadow

0 commit comments

Comments
 (0)