-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsm5test.html
101 lines (87 loc) Β· 2.25 KB
/
sm5test.html
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
98
99
100
101
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
header {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100px;
background: #ccc;
transform: translateY(0%);
transition: .3s;
}
header.on {
background: #f00;
}
header.hidden {
transform: translateY(-100%);
}
.container {
max-width: 98%;
margin: 0 auto;
}
.container [class*='box'] {
width: 100%;
height: 600px;
margin-top: 20px;
border: 3px solid #ccc;
}
.container .green {
border: none;
background: green;
}
.fixed {
position: fixed;
bottom: 25px;
left: 25px;
width: 200px;
height: 50px;
border: 1px solid #ccc;
overflow: hidden;
}
</style>
</head>
<body>
<header class="header">
header
</header>
<main class="container">
<section class="box1"></section>
<section class="box2"></section>
<section class="box3 green"></section>
<section class="box4"></section>
<section class="box5"></section>
<section class="box6"></section>
</main>
<div class="fixed"></div>
<script>
let lastScroll = 0;
$(window).scroll(function () {
curr = $(this).scrollTop();
if (curr >= lastScroll) {
$('header').addClass('on')
} else {
$('header').removeClass('on')
}
if (curr < lastScroll) {
$('header').addClass('hidden')
} else {
$('header').removeClass('hidden')
}
lastScroll = curr;
$('.fixed').html(Math.floor(curr))
})
</script>
</body>
</html>