forked from naazzzim/fossmeet-marketing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
61 lines (60 loc) · 1.62 KB
/
script.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
function iOS() {
return [
'iPad Simulator',
'iPhone Simulator',
'iPod Simulator',
'iPad',
'iPhone',
'iPod'
].includes(navigator.platform)
|| (navigator.userAgent.includes("Mac") && "ontouchend" in document)
}
if (iOS()) {
document.getElementById('alert').style.opacity=1
document.getElementById('alert').style.zIndex=200
}
const cls = () =>{
console.log('clicked');
document.getElementById('alert').style.opacity=0
document.getElementById('alert').style.zIndex=0
}
const scr = (scrl=600)=>{ document.getElementById('main').scrollBy({
behavior:"smooth",
left:0,
top:scrl
});
console.log('clicked down');
}
const scr2 = ()=>{
document.getElementById('main').scrollBy({
behavior:'smooth',
left:0,
top:-600
})
console.log('clicked up');
}
window.sections = [...document.querySelectorAll('.section')];
window.bg = [...document.querySelectorAll('.bg-img')];
window.lastScrollTop = window.pageYOffset;
// window.bg[0].style.opacity=1
document.getElementById('main').addEventListener('scroll', onScroll);
function onScroll() {
const scrollTop = window.pageYOffset;
console.log('scrolled');
const section = window.sections
.map(section => {
const el = section;
const rect = el.getBoundingClientRect();
return {el, rect};
})
.find(section => section.rect.bottom >= (window.innerHeight * 0.5));
window.bg.forEach(x => {
x.style.opacity=0
});
if (section.el.getAttribute('data-bg')!=100) {
window.bg[section.el.getAttribute('data-bg')].style.opacity=1
}
}
if(window.outerWidth > 425) {
onScroll()
}