-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSectionHeaderStickyThing.js
99 lines (68 loc) · 3.5 KB
/
SectionHeaderStickyThing.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const aboutHeader = document.getElementById("aboutHeader")
const text = document.getElementsByClassName("aboutText");
const clientHeight = document.documentElement.clientHeight;
const startY = aboutHeader.offsetParent.offsetTop + aboutHeader.offsetTop + aboutHeader.offsetHeight - 0.65* clientHeight;
const endY = text[text.length-1].offsetParent.offsetTop+ text[text.length-1].offsetTop -0.45 * clientHeight;
// figure out how to this better..
let a = aboutHeader.offsetParent.offsetTop + aboutHeader.offsetTop;
let applyTopToSticky = true;
const imageheight = document.getElementById('titleArea').offsetHeight;
const initial = aboutHeader.offsetTop;
const initInner = aboutHeader.offsetParent.offsetTop;
const b = (document.getElementsByClassName('sectionDiv'))[0]
const red= document.getElementById('aboutDiv');
let startToEndRange = endY - startY;
let selectedImg = 1;
let selectings = document.getElementById('transition');
// also animations or smth? idfl...
//also also, have thing stay at end position when done?
function onScroll(){
if(window.scrollY > startY && window.scrollY < endY){
if (applyTopToSticky) {
aboutHeader.classList.add("activeHeader");
aboutHeader.style.marginTop = '0px';
let b = a - startY;
aboutHeader.style.top = b.toString() + "px";
applyTopToSticky = false;
}
aboutHeader.classList.remove("endHeader");
}
else if(window.scrollY >= endY){
if (!applyTopToSticky){
aboutHeader.classList.remove("activeHeader");
aboutHeader.classList.add('endHeader');
let b = endY - initInner + aboutHeader.offsetTop;
aboutHeader.style.marginTop = '0px';
aboutHeader.style.top = b.toString() + 'px';
}
applyTopToSticky = true;
}
else{
if(!applyTopToSticky) {
aboutHeader.classList.remove("activeHeader");
let b = initial;
aboutHeader.style.marginTop = '0px';
aboutHeader.style.top = b.toString() + 'px';
}
applyTopToSticky = true;
}
// so basically we transition between 3 images, so we divide the range thing by 3. initially our selectimg is 1..
/*
and basically if our scrolling is greater than the supertop image(the blackpink thing u have) which is a constant plus a third
etc then we switch img
else if it is less than our no change area (like the part where we dont change img-we have 3 of these and each of them is roughly range/3
idk if this make sense but like the area where we no change) then we switch- code works i think u can check.
ALSO i notice that the second image may not get enough time like its range is small compared to the other ones so if you
want to edit it then edit and change the region of selectedImg * startToEndRange/3 part like you could add a constant or do like 2/5 instead of 1/3
ur choice
*/
if(window.scrollY >= (initInner + selectedImg * startToEndRange/3) && selectedImg != selectedImg + 1 && selectedImg <3) {
selectedImg++;
selectings.style.backgroundImage = 'url("images/bbusinessimgfiller' + selectedImg.toString() + '.jpeg")';
}
else if (window.scrollY <(initInner + (selectedImg-1) * startToEndRange/3) && selectedImg >1){
selectedImg--;
selectings.style.backgroundImage = 'url("images/bbusinessimgfiller' + selectedImg.toString() + '.jpeg")';}
}
window.addEventListener('scroll', onScroll)
// supposed be around 830