-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
49 lines (49 loc) · 1.48 KB
/
index.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
let ph;
function init() {
ph=window.innerHeight;
$(':root').css('--ph',`${ph}px`);
if(window.innerWidth<550){
$(':root').addClass('mobile');
}else{
$(':root').removeClass('mobile');
};
}
init();
let pics=document.querySelectorAll('#content>*');
document.addEventListener('scroll',()=>{
let t=$('html').scrollTop();
pics.forEach(pic => {
if($(pic).hasClass('show')){
if(pic.offsetTop+(pic.offsetHeight * 0.3)<t){
$(pic).removeClass('show');
$(pic).addClass('bf');
}else if(pic.offsetTop+(pic.offsetHeight * 0.7)>t+ph){
$(pic).removeClass('show');
$(pic).addClass('af');
}
}else{
// let pct=pic.offsetTop+(pic.offsetHeight * 0.5);
if(pic.offsetTop+(pic.offsetHeight * 0.3)>=t && pic.offsetTop+(pic.offsetHeight * 0.7)<=t+ph){
$(pic).addClass('show');
$(pic).removeClass('bf');
$(pic).removeClass('af');
}
}
});
if(t==0){
pics.forEach(pic=>{
$(pic).removeClass('show');
$(pic).removeClass('bf');
$(pic).addClass('af');
});
}
if($('#tip').hasClass('show'))$('#tip').removeClass('show');
});
window.onresize=init;
$('body')[0].onload=()=>{
// $('html')[0].scroll(0,0);
// setTimeout(() => {
// $('html')[0].scroll(0,0);
// }, 100);()=>{
$('html,#cover').addClass('load');
};